#include "common/viewmgr.h"
#include "common/inputmgr.h"
#include "common/utils.h"
+#include "view/common/view_generic_popup.h"
#define GENERIC_POPUP_BTN_NAME_MAX 128
#define BUTTON_BOX_PADDING 8
+#define FOCUS_DIR_TYPES 2
struct _priv {
Evas_Object *popup;
- Evas_Object *layout;
+ Evas_Object *box;
Eina_List *popup_buttons;
int (*ui_id_on_show_focus)(void);
};
static void _hide(void *view_data);
static void _destroy(void *view_data);
+void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev);
+
+static input_handler _input_handler = {
+ .key_down = _key_down_cb,
+};
+
/* Helper: */
-static bool _fill_popup_btns(struct _priv *priv, Evas_Object *layout,
- int btn_count, const char **btn_text, input_handler *handler);
+static bool _fill_items(struct _priv *priv, Evas_Object *popup, int item_count, const char **item_text, input_handler *handler);
static view_class _vclass = {
.view_id = NULL,
static Evas_Object *_create(Evas_Object *win, void *data)
{
+ SETTING_TRACE_BEGIN;
struct _priv *priv = NULL;
generic_popup_attr *g_data = (generic_popup_attr *)data;
return NULL;
}
- priv->popup = utils_add_popup(win, NULL, g_data->popup_title, NULL);
+ priv->popup = utils_add_layout(win, g_data->popup_layout_group, EINA_TRUE);
if (!priv->popup) {
- _ERR("Add popup failed");
- free(priv);
- return NULL;
- }
-
- priv->layout = utils_add_layout(priv->popup, g_data->popup_layout_group, EINA_FALSE);
- if (!priv->layout) {
_ERR("Add layout failed.");
evas_object_del(priv->popup);
free(priv);
return NULL;
}
- elm_object_part_text_set(priv->layout, PART_POPUP_NAME, g_data->popup_description);
+ elm_object_part_text_set(priv->popup, PART_POPUP_TITLE, g_data->popup_title);
- if (!_fill_popup_btns(priv, priv->layout, g_data->buttns_count, g_data->btn_texts, g_data->handler)) {
- evas_object_del(priv->popup);
- free(priv);
- return NULL;
+ if (g_data->items_count != 0) {
+ _fill_items(priv, priv->popup, g_data->items_count, g_data->item_texts, g_data->handler);
}
- priv->ui_id_on_show_focus = g_data->ui_id_on_show_focus;
-
- elm_object_content_set(priv->popup, priv->layout);
-
+ inputmgr_add_callback(priv->popup, 0, &_input_handler, NULL);
g_data->generic_popup_data = priv;
+ SETTING_TRACE_END;
return priv->popup;
}
static void _show(void *data)
{
- Evas_Object *ui_element_to_focus = NULL;
- int ui_id_to_focus = 0;
+ SETTING_TRACE_BEGIN;
struct _priv *priv = (struct _priv *)data;
+ Eina_List *children = NULL;
+ Evas_Object *first = NULL;
if (!priv) {
_ERR("Invalid parameter.");
return;
}
- evas_object_show(priv->popup);
-
- if(priv->ui_id_on_show_focus) {
- ui_id_to_focus = priv->ui_id_on_show_focus();
+ children = elm_box_children_get(priv->box);
+ first = eina_list_data_get(children);
+ elm_object_focus_set(first, EINA_TRUE);
- ui_element_to_focus = eina_list_nth(priv->popup_buttons, ui_id_to_focus);
- if (!ui_element_to_focus) {
- _ERR("ui_element_to_focus == NULL");
- return;
- }
- elm_object_focus_set(ui_element_to_focus, EINA_TRUE);
- }
+ evas_object_show(priv->popup);
+ SETTING_TRACE_END;
}
static void _hide(void *data)
{
+ SETTING_TRACE_BEGIN;
struct _priv *priv = (struct _priv *)data;
if (!priv) {
}
evas_object_hide(priv->popup);
+ SETTING_TRACE_END;
}
static void _destroy(void *data)
{
+ SETTING_TRACE_BEGIN;
struct _priv *priv = (struct _priv *)data;
if (!priv) {
evas_object_del(priv->popup);
free(priv);
+ SETTING_TRACE_END;
}
-static bool _fill_popup_btns(struct _priv *priv, Evas_Object *layout,
- int btn_count, const char **btn_text, input_handler *handler)
+inline static void _focus_link_set(Evas_Object *prev, Evas_Object *next,
+ Elm_Focus_Direction *next_dirs, Elm_Focus_Direction *prev_dirs,
+ int count)
{
- int i = 0;
- Evas_Object *btn = NULL;
- Evas_Object *scroller = NULL;
- Evas_Object *box = NULL;
-
- scroller = elm_scroller_add(layout);
- if (!scroller) {
- _ERR("scroller == NULL");
- return false;
- }
+ int i;
+ for (i = 0; i < count; ++i) {
+ elm_object_focus_next_object_set(prev, next, next_dirs[i]);
- elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_ON);
+ if (prev_dirs)
+ elm_object_focus_next_object_set(next, prev, prev_dirs[i]);
+ }
+}
- box = elm_box_add(scroller);
- if (!box) {
- _ERR("box == NULL");
- return false;
+static void _focus_chain_set(Evas_Object *box, bool is_last)
+{
+ Elm_Focus_Direction next_types[FOCUS_DIR_TYPES] = {ELM_FOCUS_DOWN, ELM_FOCUS_NEXT};
+ Elm_Focus_Direction prev_types[FOCUS_DIR_TYPES] = {ELM_FOCUS_UP, ELM_FOCUS_PREVIOUS};
+ Elm_Focus_Direction left_right[FOCUS_DIR_TYPES] = {ELM_FOCUS_LEFT, ELM_FOCUS_RIGHT};
+ Eina_List *children = elm_box_children_get(box);
+ Eina_List *last = eina_list_last(children);
+ Eina_List *prev = eina_list_prev(last);
+ Evas_Object *obj_last = eina_list_data_get(last);
+ Evas_Object *obj_prev = eina_list_data_get(prev);
+
+ _focus_link_set(obj_last, obj_last, left_right, NULL, FOCUS_DIR_TYPES);
+
+ if (!obj_prev) {
+ _focus_link_set(obj_last, obj_last, prev_types, NULL, FOCUS_DIR_TYPES);
+ return;
}
- evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_box_padding_set(box, BUTTON_BOX_PADDING, BUTTON_BOX_PADDING);
+ _focus_link_set(obj_last, obj_prev, prev_types, next_types, FOCUS_DIR_TYPES);
- for(i = 0; i < btn_count; i++) {
- btn = elm_button_add(box);
- if (!btn) {
- _ERR("Add button failed.");
- return false;
- }
+ if (is_last)
+ _focus_link_set(obj_last, obj_last, next_types, NULL, FOCUS_DIR_TYPES);
+}
- evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_object_text_set(btn, btn_text[i]);
- elm_box_pack_end(box, btn);
- evas_object_show(btn);
+static void _focus_chain_debug(Evas_Object *box)
+{
+ int i = 0;
+ Elm_Focus_Direction dir = 0;
+ Eina_List *children = elm_box_children_get(box);
+ int count = eina_list_count(children);
+ Evas_Object *item;
+ Evas_Object *focus_to;
+ const char *text;
+
+ char *dir_names[] = {
+ "ELM_FOCUS_PREVIOUS",
+ "ELM_FOCUS_NEXT",
+ "ELM_FOCUS_UP",
+ "ELM_FOCUS_DOWN",
+ "ELM_FOCUS_RIGHT",
+ "ELM_FOCUS_LEFT",
+ };
+
+ for (i = 0; i < count; ++i) {
+ item = eina_list_nth(children, i);
+
+ text = elm_object_text_get(item);
+ dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ITEM: %s", __FILE__, __LINE__, text);
+
+ for (dir = 0; dir < sizeof(dir_names) / sizeof(dir_names[0]); ++dir) {
+
+ focus_to = elm_object_focus_next_object_get(item, dir);
+ text = elm_object_text_get(focus_to);
+ dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] >>>>>>>>>>> %s: %s", __FILE__, __LINE__, dir_names[dir], text);
+ }
+ }
+}
- inputmgr_add_callback(btn, i, handler, priv);
+static bool _fill_items(struct _priv *priv, Evas_Object *popup, int item_count, const char **item_text, input_handler *handler)
+{
+ Evas_Object *radio = NULL;
+ priv->box = elm_box_add(priv->popup);
+ elm_box_horizontal_set(priv->box, EINA_FALSE);
+
+ evas_object_size_hint_weight_set(priv->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(priv->box, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_min_set(priv->box, 300, 300);
+
+ int i;
+ for (i = 0; i < item_count; i++) {
+ radio = utils_add_radio(priv->box, NULL, NULL, item_text[i % item_count]);
+ evas_object_size_hint_min_set(radio, 300, 50);
+ evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(radio);
+ elm_box_pack_end(priv->box, radio);
+ _focus_chain_set(priv->box, i == item_count - 1);
+
+ inputmgr_add_callback(radio, i, handler, NULL);
}
- elm_layout_content_set(layout, PART_POPUP_BTN_BOX, scroller);
- elm_object_content_set(scroller, box);
- priv->popup_buttons = elm_box_children_get(box);
+ elm_object_part_content_set(priv->popup, PART_POPUP_LIST, priv->box);
+ _focus_chain_debug(priv->box);
return true;
}
+
+void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
+{
+ if (!obj || !ev) {
+ _ERR("Invalid argument.");
+ return;
+ }
+
+ if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_WAY) ||
+ !strcmp(ev->keyname, KEY_ESC) || !strcmp(ev->keyname, KEY_ESC_WAY)) {
+ viewmgr_pop_view();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 <app.h>
+#include <Elementary.h>
+#include <time.h>
+
+#include "common/viewmgr.h"
+#include "common/inputmgr.h"
+#include "app_debug.h"
+#include "define.h"
+#include "common/utils.h"
+#include "view/system/view_clock.h"
+#include "view/common/view_generic_popup.h"
+#include "data/system/settings_clock.h"
+#include "app_string.h"
+
+#define BUTTON_RETURN 36
+
+enum setup_type {
+ TYPE_MANUAL = 0,
+ TYPE_AUTO,
+ TYPE_MAX
+};
+
+static const char *str_setup_type_opt[] = {
+ STR_MANUAL,
+ STR_AUTO
+};
+
+typedef struct {
+ Evas_Object *win;
+ Evas_Object *ly;
+ Evas_Object *conformant;
+
+ enum setup_type cur_type;
+ bool input_panel_show;
+ Evas_Object *focused_entry;
+
+} clock_mode_view_priv_data;
+
+static void _popup_item_selected_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev);
+
+static input_handler _input_handler = {
+ .key_down = _popup_item_selected_cb,
+};
+
+static Evas_Object *_create(Evas_Object *win, void *data)
+{
+ SETTING_TRACE_BEGIN;
+ view_class *vc = view_generic_popup_get_vclass();
+ generic_popup_attr *g_data = NULL;
+
+ if (!win) {
+ _ERR("Get window object failed.");
+ return NULL;
+ }
+
+ g_data = calloc(1, sizeof(generic_popup_attr));
+ if (!g_data) {
+ _ERR("Calloc failed.");
+ return NULL;
+ }
+
+ g_data->popup_title = "Clock";
+ g_data->popup_description = NULL;
+ g_data->popup_layout_group = GRP_VIEW_POPUP_LIST;
+ g_data->handler = &_input_handler;
+ g_data->buttns_count = 0;
+ g_data->btn_texts = NULL;
+ g_data->items_count = sizeof(str_setup_type_opt) / sizeof(str_setup_type_opt[0]);
+ g_data->item_texts = calloc(g_data->items_count, sizeof(char *));
+ g_data->ui_id_on_show_focus = NULL;
+ g_data->generic_popup_data = NULL;
+
+ int i;
+ for(i = 0; i < sizeof(str_setup_type_opt) / sizeof(str_setup_type_opt[0]); ++i) {
+ g_data->item_texts[i] = str_setup_type_opt[i];
+ }
+
+ if (!viewmgr_set_view_data(VIEW_CLOCK_MODE, g_data)) {
+ free(g_data);
+ _ERR("Set view data failed.");
+ return NULL;
+ }
+
+ SETTING_TRACE_END;
+ return vc->create(win, g_data);
+}
+
+static void _popup_item_selected_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev)
+{
+ dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] BUTTON = %d", __FILE__, __LINE__, ev->keycode);
+ if (ev->keycode != BUTTON_RETURN)
+ return;
+
+ viewmgr_pop_view();
+
+ if (id == TYPE_MANUAL) {
+ settings_clock_set_time_automatic(true);
+ viewmgr_show_view(VIEW_CLOCK);
+ } else {
+ settings_clock_set_time_automatic(true);
+ }
+
+ viewmgr_update_view(VIEW_BASE, UPDATE_CONTENT, NULL);
+}
+
+static void _show(void *data)
+{
+ SETTING_TRACE_BEGIN
+ generic_popup_attr *g_data = data;
+ view_class *vc = view_generic_popup_get_vclass();
+ vc->show(g_data->generic_popup_data);
+ SETTING_TRACE_END
+}
+
+static void _hide(void *data)
+{
+ SETTING_TRACE_BEGIN;
+ generic_popup_attr *g_data = data;
+ view_class *vc = view_generic_popup_get_vclass();
+ vc->hide(g_data->generic_popup_data);
+ SETTING_TRACE_END;
+}
+
+static void _destroy(void *data)
+{
+ SETTING_TRACE_BEGIN;
+ generic_popup_attr *g_data = data;
+ view_class *vc = view_generic_popup_get_vclass();
+ vc->destroy(g_data->generic_popup_data);
+ SETTING_TRACE_END;
+}
+
+static view_class _vclass = {
+ .view_id = VIEW_CLOCK_MODE,
+ .create = _create,
+ .show = _show,
+ .hide = _hide,
+ .destroy = _destroy,
+};
+
+view_class *view_clock_mode_get_vclass(void)
+{
+ return &_vclass;
+}