2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * PROPRIETARY/CONFIDENTIAL
6 * This software is the confidential and proprietary information of
7 * SAMSUNG ELECTRONICS ("Confidential Information").
8 * You shall not disclose such Confidential Information and shall
9 * use it only in accordance with the terms of the license agreement
10 * you entered into with SAMSUNG ELECTRONICS.
11 * SAMSUNG make no representations or warranties about the suitability
12 * of the software, either express or implied, including but not
13 * limited to the implied warranties of merchantability, fitness for
14 * a particular purpose, or non-infringement.
15 * SAMSUNG shall not be liable for any damages suffered by licensee as
16 * a result of using, modifying or distributing this software or its derivatives.
24 #include <pkgmgr-info.h>
27 #include "nsa-debug.h"
29 #include "nsa-ui-widget.h"
30 #include "nsa-popup.h"
31 #include "nsa-string.h"
42 Elm_Object_Item *obj_item[T_MAX];
49 static main_view_data_t *view_data;
50 static char *payment_handler;
52 ///////////////////////////////////////////////////////////////////////////////
54 static Eina_Bool __back_clicked_cb(void *data, Elm_Object_Item *it)
56 main_view_data_t *vd = (main_view_data_t *)data;
58 NSA_DEBUG("__back_clicked_cb");
61 struct appdata *ad = vd->ad;
63 _nsa_view_main_destroy(ad);
72 static void __MDM_restriced_popup_response_cb(void *data,
73 Evas_Object *obj, void *event_info)
75 main_view_data_t *vd = (main_view_data_t *)data;
80 ad = (struct appdata *)vd->ad;
84 ret_if(ad->popup == NULL);
86 NSA_DEBUG("__MDM_restriced_popup_response_cb");
88 elm_popup_dismiss(ad->popup);
92 static main_view_data_t *__get_view_data()
97 static void __set_view_data(main_view_data_t *data)
102 static void __get_payment_handler(char **handler)
106 NSA_MEM_FREE(*handler);
108 appid = vconf_get_str(VCONFKEY_NFC_PAYMENT_HANDLERS);
111 pkgmgrinfo_pkginfo_h pkginfo = NULL;
115 ret = pkgmgrinfo_pkginfo_get_pkginfo(appid, &pkginfo);
120 ret = pkgmgrinfo_pkginfo_get_label(pkginfo, &label);
122 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
125 NSA_MEM_STRDUP(*handler, label);
126 if (*handler != NULL)
127 NSA_DEBUG("text: %s", *handler);
129 pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
134 static void __update_onoff_obj(void *data)
136 main_view_data_t *vd = (main_view_data_t *)data;
141 it = vd->obj_item[T_NFC];
144 NSA_DEBUG("__update_onoff_obj");
146 /* V1.9 : instead of toast popup, disable item during operation */
147 elm_object_item_disabled_set(it, false);
148 elm_genlist_item_fields_update(it, "*",
149 ELM_GENLIST_ITEM_FIELD_CONTENT);
152 static void __update_tap_and_pay_obj(bool activated, void *data)
154 main_view_data_t *vd = (main_view_data_t *)data;
159 it = vd->obj_item[T_TAP_N_PAY];
164 elm_object_item_disabled_set(it, false);
166 elm_object_item_disabled_set(it, true);
168 elm_genlist_item_fields_update(it, "*",
169 ELM_GENLIST_ITEM_FIELD_TEXT);
172 static void __handle_nfc_activation_completed_event(bool activated,
173 main_view_data_t *data)
175 main_view_data_t *vd = (main_view_data_t *)data;
180 NSA_DEBUG("activated [%d]", activated);
183 __update_onoff_obj(vd);
184 __update_tap_and_pay_obj(activated, vd);
187 static void __nfc_vconf_key_changed (keynode_t *key, void *data)
189 main_view_data_t *vd = (main_view_data_t *)data;
193 g_assert(vd != NULL);
195 if (VCONF_OK != vconf_get_bool(VCONFKEY_NFC_STATE, &boolval)) {
205 NSA_DEBUG("boolval %d", boolval);
206 NSA_DEBUG("nfc mode %s ", activated ? "ON" : "OFF");
208 if (!vd->isProgressing) {
209 __handle_nfc_activation_completed_event(activated, vd);
213 static void __payment_handler_vconf_key_changed (keynode_t *key,
216 main_view_data_t *vd = (main_view_data_t *)data;
218 NSA_DEBUG("__payment_handler_vconf_key_changed");
220 /* Get changed payment handler */
221 __get_payment_handler(&payment_handler);
223 /* update tap and pay */
224 if (nfc_manager_is_activated()) {
225 __update_tap_and_pay_obj(true, vd);
227 __update_tap_and_pay_obj(false, vd);
231 /* called when ifself performs activation */
232 /* vd->isProgressing is set by itself */
233 static void __nfc_activation_completed_cb(nfc_error_e error,
236 main_view_data_t *vd = (main_view_data_t *)user_data;;
239 g_assert(vd != NULL);
241 /* handle error cases */
242 if (error != NFC_ERROR_NONE) {
243 NSA_DEBUG_ERR("__nfc_activation_completed_cb failed");
246 /* update ui after activation is completed */
247 if (vd->isProgressing) {
248 vd->isProgressing = false;
249 activated = nfc_manager_is_activated();
251 __handle_nfc_activation_completed_event(activated, vd);
255 /* called when someone performs activation except for itself */
256 static void __nfc_activation_changed_cb(bool activated , void *user_data)
258 main_view_data_t *vd = (main_view_data_t *)user_data;
260 g_assert(vd != NULL);
262 NSA_DEBUG("nfc mode %s ", activated ? "ON" : "OFF");
264 if (!vd->isProgressing) {
265 __handle_nfc_activation_completed_event(activated, vd);
269 static void __change_nfc_onoff_setting(void *data)
271 main_view_data_t *vd = (main_view_data_t *)data;
280 /* V1.9 : instead of toast popup, disable item during operation */
281 it = vd->obj_item[T_NFC];
283 elm_object_item_disabled_set(it, true);
285 activated = nfc_manager_is_activated();
287 result = nfc_manager_set_activation(!activated,
288 __nfc_activation_completed_cb, vd);
289 ret_if(result != NFC_ERROR_NONE);
291 vd->isProgressing = true;
296 static void __gl_list_clicked_cb(void *data, Evas_Object *obj,
299 Elm_Object_Item* it = (Elm_Object_Item *)event_info;
301 main_view_data_t *vd;
306 vd = __get_view_data();
312 elm_genlist_item_selected_set(it, EINA_FALSE);
314 NSA_DEBUG("__gl_list_clicked_cb");
317 if(!__is_nfc_allowed(ad)) {
318 __update_onoff_obj(vd);
322 ad->popup = nsa_create_popup_text_1button(
324 IDS_SECURITY_POLICY_PREVENTS_USE_OF_NFC_ABB,
325 IMAGES_PATH"/tw_ic_popup_btn_check.png",
326 __MDM_restriced_popup_response_cb,
329 nsa_create_toast_popup(ad->ly_main,
330 IDS_SECURITY_POLICY_PREVENTS_USE_OF_NFC_ABB);
336 if (index == T_NFC) {
337 __change_nfc_onoff_setting(vd);
338 } else if (index == T_TAP_N_PAY){
339 _nsa_view_tap_n_pay_create(ad);
345 static Evas_Object *__gl_content_get_on_off(void *data, Evas_Object *obj,
348 main_view_data_t *vd;
355 vd = __get_view_data();
356 retv_if(vd == NULL, NULL);
358 if (!strcmp(part, "elm.icon")) {
359 check = elm_check_add(obj);
360 retv_if(check == NULL, NULL);
361 elm_access_object_unregister(check);
362 elm_object_style_set(check, "on&off/list");
364 if (index == T_NFC) {
365 if (VCONF_OK != vconf_get_bool(VCONFKEY_NFC_STATE, &boolval)) {
366 elm_check_state_set(check, EINA_FALSE);
369 elm_check_state_set(check, EINA_TRUE);
371 elm_check_state_set(check, EINA_FALSE);
375 evas_object_size_hint_align_set(check, EVAS_HINT_FILL,
377 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND,
379 evas_object_propagate_events_set(check, EINA_FALSE);
380 evas_object_repeat_events_set(check, EINA_TRUE);
388 static char *__gl_text_get_title(void *data, Evas_Object *obj,
391 //NSA_DEBUG("part:%s", part);
393 if (!strcmp(part, "elm.text")) {
394 return strdup(IDS_NFC_NFC);
400 static char *__gl_text_get(void *data, Evas_Object *obj,
403 int index = (int)data;
405 //NSA_DEBUG("index:%d", index);
406 //NSA_DEBUG("part:%s", part);
408 if (!strcmp(part, "elm.text")) {
409 if (index == T_NFC) {
410 return strdup(IDS_NFC_NFC);
411 } else if (index == T_TAP_N_PAY){
412 return strdup(IDS_TAP_AND_PAY);
416 } else if (!strcmp(part, "elm.text.1")) {
417 if (index == T_TAP_N_PAY) {
418 if (payment_handler != NULL)
419 return strdup(payment_handler);
430 static Evas_Object *__create_nfc_setting_list(void *data)
432 main_view_data_t *vd = (main_view_data_t *)data;
434 Evas_Object *genlist;
435 Elm_Genlist_Item_Class *itc_title, *itc_on_off, *itc_list;
436 Evas_Object *circle_obj;
439 retv_if(vd == NULL, NULL);
442 retv_if(ad == NULL, NULL);
445 genlist = elm_genlist_add(vd->nf);
446 retv_if(genlist == NULL, NULL);
448 /* set genlist property */
449 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
450 // elm_genlist_homogeneous_set(genlist, EINA_TRUE);
451 // uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
453 circle_obj = eext_circle_object_genlist_add(genlist,
455 eext_circle_object_genlist_scroller_policy_set(circle_obj,
456 ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
457 eext_rotary_object_event_activated_set(circle_obj, EINA_TRUE);
458 g_array_append_val(ad->circle_obj_list, circle_obj);
459 ad->circle_obj_list_idx ++;
460 NSA_DEBUG("ad->circle_obj_list_idx %d", ad->circle_obj_list_idx);
461 NSA_DEBUG("circle_obj 0x%p", circle_obj);
463 /* create genlist class + */
464 itc_title = elm_genlist_item_class_new();
465 itc_title->item_style = "title";
466 itc_title->func.text_get = __gl_text_get_title;
467 itc_title->func.content_get = NULL;
468 itc_title->func.del = NULL;
470 itc_on_off = elm_genlist_item_class_new();
471 itc_on_off->item_style = "1text.1icon.1";
472 itc_on_off->func.text_get = __gl_text_get;
473 itc_on_off->func.content_get = __gl_content_get_on_off;
474 itc_on_off->func.state_get = NULL;
475 itc_on_off->func.del = NULL;
477 itc_list = elm_genlist_item_class_new();
478 __get_payment_handler(&payment_handler);
479 if (payment_handler != NULL)
480 itc_list->item_style = "2text";
482 itc_list->item_style = "1text";
483 itc_list->func.text_get = __gl_text_get;
484 itc_list->func.content_get = NULL;
485 itc_list->func.state_get = NULL;
486 itc_list->func.del = NULL;
487 /* create genlist class - */
490 elm_genlist_item_append(genlist,
492 NULL, ELM_GENLIST_ITEM_NONE,
495 for (i = 0; i < T_MAX; i++) {
496 Elm_Genlist_Item_Class *itc;
503 vd->obj_item[i] = elm_genlist_item_append(genlist,
505 NULL, ELM_GENLIST_ITEM_NONE,
506 __gl_list_clicked_cb, (void *)i);
509 elm_genlist_item_class_free(itc_title);
510 elm_genlist_item_class_free(itc_on_off);
511 elm_genlist_item_class_free(itc_list);
514 if (!nfc_manager_is_activated())
515 __update_tap_and_pay_obj(false, vd);
517 evas_object_show(genlist);
522 int _nsa_view_main_create(void *data)
524 struct appdata *ad = (struct appdata *)data;
525 main_view_data_t *vd;
529 NSA_MEM_MALLOC(vd, 1, main_view_data_t);
530 retv_if(vd == NULL, NSA_ERROR);
534 /* set appdata to main view data */
535 vd->nf = ad->navi_frame;
538 list = __create_nfc_setting_list(vd);
539 retv_if(list == NULL, NSA_ERROR);
541 /* Push navifreme + */
542 eext_object_event_callback_add(vd->nf, EEXT_CALLBACK_BACK,
543 eext_naviframe_back_cb, NULL);
545 ad->base_navi_it = elm_naviframe_item_push(
552 elm_naviframe_item_pop_cb_set(ad->base_navi_it, __back_clicked_cb,
554 /* Push navifreme - */
556 /* register nfc callback */
557 nfc_manager_set_activation_changed_cb(
558 __nfc_activation_changed_cb, vd);
560 if (VCONF_OK != vconf_notify_key_changed(VCONFKEY_NFC_STATE,
561 __nfc_vconf_key_changed, vd)) {
562 NSA_DEBUG_ERR("vconf_notify_key_changed error");
565 if (VCONF_OK != vconf_notify_key_changed(VCONFKEY_NFC_PAYMENT_HANDLERS,
566 __payment_handler_vconf_key_changed, vd)) {
567 NSA_DEBUG_ERR("vconf_notify_key_changed error");
573 void _nsa_view_main_destroy(void *data)
577 __set_view_data(NULL);
579 /* unregister nfc callback */
580 nfc_manager_unset_activation_changed_cb();
582 if (VCONF_OK != vconf_ignore_key_changed(VCONFKEY_NFC_STATE,
583 __nfc_vconf_key_changed)) {
584 NSA_DEBUG_ERR("vconf_notify_key_changed error");
587 if (VCONF_OK != vconf_ignore_key_changed(VCONFKEY_NFC_PAYMENT_HANDLERS,
588 __payment_handler_vconf_key_changed)) {
589 NSA_DEBUG_ERR("vconf_ignore_key_changed error");
592 ad = (struct appdata *)data;