1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
*
* Licensed under the Flora License, Version 1.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://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 "ug-nfc-setting-popup.h"
#define NFC_POPUP_AUTO_TIMEOUT_SEC 3.0
#define MOUSE_RIGHT_BTN_UP 3
#define KEY_BACK "XF86Back"
static Evas_Object *_popup = NULL;
static UG_NFC_POPUP_USER_RESP_CB _user_response_cb;
static void *_user_data = NULL;
static void _remove_key_event_handler(void);
static void _add_key_event_handler(void);
static void _ug_nfc_setting_popup_response_cb(void *data, Evas_Object *obj, void *event_info)
{
int btn_type = (int)data;
if (_user_response_cb)
_user_response_cb(_user_data, obj, (void*)btn_type);
LOGD("btn_type: %d", (int)btn_type);
LOGD("Popup is removed: [%p]", obj);
evas_object_del(_popup);
_popup = NULL;
_user_response_cb = NULL;
_user_data = NULL;
}
static Eina_Bool _ug_nfc_setting_popup_show_cb(void *data)
{
if (_popup)
evas_object_show(_popup);
return ECORE_CALLBACK_CANCEL;
}
static void _popup_back_click_cb(void)
{
if (!_popup)
return;
_remove_key_event_handler();
_ug_nfc_setting_popup_response_cb((void*)UG_NFC_POPUP_RESP_CANCEL, _popup, NULL);
}
static void _mouseup_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Mouse_Up *ev = event_info;
if (!ev)
return;
if (ev->button == MOUSE_RIGHT_BTN_UP)
_popup_back_click_cb();
}
static void _keydown_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
Evas_Event_Key_Down *ev = event_info;
if (!ev)
return;
if (!strcmp(ev->keyname, KEY_BACK))
_popup_back_click_cb();
}
static void _remove_key_event_handler(void)
{
if (!_popup)
return;
evas_object_event_callback_del(_popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_cb);
evas_object_event_callback_del(_popup, EVAS_CALLBACK_KEY_DOWN, _keydown_cb);
}
static void _add_key_event_handler(void)
{
if (!_popup)
return;
evas_object_event_callback_add(_popup, EVAS_CALLBACK_MOUSE_UP, _mouseup_cb, NULL);
evas_object_event_callback_add(_popup, EVAS_CALLBACK_KEY_DOWN, _keydown_cb, NULL);
}
static void _ug_nfc_setting_popup_block_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
_ug_nfc_setting_popup_response_cb((void*)UG_NFC_POPUP_RESP_CANCEL, _popup, NULL);
}
Evas_Object *ug_nfc_setting_create_popup(void *data,
Evas_Object *parent_layout,
const char *title,
const char *description,
const char *btn1_text,
int btn1_type,
const char *btn2_text,
int btn2_type,
const char *btn3_text,
int btn3_type,
bool is_alert_type,
bool enable_timeout,
UG_NFC_POPUP_USER_RESP_CB response_cb)
{
Evas_Object *btn = NULL;
if (data == NULL)
return NULL;
if (_popup) {
ug_nfc_setting_close_popup(_popup);
_popup = NULL;
}
_popup = elm_popup_add(parent_layout);
LOGD("Popup is created: [%p]", _popup);
evas_object_size_hint_weight_set(_popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
if (title)
elm_object_part_text_set(_popup, "title,text", title);
elm_object_text_set(_popup, description);
if(btn1_text) {
btn = elm_button_add(_popup);
elm_object_style_set (btn, "popup");
elm_object_text_set(btn, btn1_text);
elm_object_part_content_set(_popup, "button1", btn);
evas_object_smart_callback_add(btn, "clicked",
_ug_nfc_setting_popup_response_cb, (void*)btn1_type);
}
if (btn2_text) {
btn = elm_button_add(_popup);
elm_object_style_set (btn, "popup");
elm_object_text_set(btn, btn2_text);
elm_object_part_content_set(_popup, "button2", btn);
evas_object_smart_callback_add(btn, "clicked",
_ug_nfc_setting_popup_response_cb, (void*)btn2_type);
}
if (btn3_text) {
btn = elm_button_add(_popup);
elm_object_style_set (btn, "popup");
elm_object_text_set(btn, btn3_text);
elm_object_part_content_set(_popup, "button3", btn);
evas_object_smart_callback_add(btn, "clicked",
_ug_nfc_setting_popup_response_cb, (void*)btn3_type);
}
_user_response_cb = response_cb;
_user_data = data;
if (is_alert_type) {
evas_object_smart_callback_add(_popup, "block,clicked",
_ug_nfc_setting_popup_block_clicked_cb, NULL);
}
if (enable_timeout) {
elm_popup_timeout_set(_popup, NFC_POPUP_AUTO_TIMEOUT_SEC);
evas_object_smart_callback_add(_popup, "timeout",
_ug_nfc_setting_popup_response_cb, NULL);
}
_add_key_event_handler();
_ug_nfc_setting_popup_show_cb(NULL);
return _popup;
}
void ug_nfc_setting_close_popup(Evas_Object* popup)
{
if (NULL == popup || NULL == _popup || _popup != popup) {
LOGD("NULL == popup || NULL == _popup || _popup != popup");
}
_ug_nfc_setting_popup_response_cb((void*)UG_NFC_POPUP_RESP_CANCEL, _popup, NULL);
}
|