2 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <Ecore_Evas.h>
20 #include <atspi/atspi.h>
21 #include <tone_player.h>
23 #include "screen_reader_tts.h"
24 #include "screen_reader_haptic.h"
25 #include "smart_notification.h"
27 #define RED "\x1B[31m"
28 #define RESET "\033[0m"
30 static Eina_Bool status = EINA_FALSE;
32 static void _smart_notification_focus_chain_end(void);
33 static void _smart_notification_realized_items(int start_idx, int end_idx);
36 * @brief Smart Notifications event handler
38 * @param nt Notification event type
39 * @param start_index int first visible items index smart_notification_realized_items
40 * @param end_index int last visible items index used for smart_notification_realized_items
42 void smart_notification(Notification_Type nt, int start_index, int end_index)
50 case FOCUS_CHAIN_END_NOTIFICATION_EVENT:
51 _smart_notification_focus_chain_end();
53 case REALIZED_ITEMS_NOTIFICATION_EVENT:
54 _smart_notification_realized_items(start_index, end_index);
57 DEBUG("Gesture type %d not handled in switch", nt);
62 * @brief Used for getting first and last index of visible items
64 * @param scrollable_object AtspiAccessible object on which scroll was triggered
65 * @param start_index int first visible items index smart_notification_realized_items
66 * @param end_index int last visible items index used for smart_notification_realized_items
68 void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx, int *end_idx)
72 AtspiAccessible *child_iter;
73 AtspiStateType state = ATSPI_STATE_SHOWING;
75 if(!scrollable_object)
77 DEBUG("No scrollable object");
81 count_child = atspi_accessible_get_child_count(scrollable_object, NULL);
83 for(jdx = 0; jdx < count_child; jdx++)
85 child_iter = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
86 if (!child_iter) continue;
88 AtspiStateSet* state_set = atspi_accessible_get_state_set(child_iter);
90 gboolean is_visible = atspi_state_set_contains(state_set, state);
94 DEBUG("Item with index %d is visible", jdx);
97 DEBUG("Item with index %d is NOT visible", jdx);
99 *end_idx = *start_idx + 8;
103 * @brief Scroll-start/Scroll-end event callback
105 * @param event AtspiEvent
106 * @param user_data UNUSED
110 _scroll_event_cb(AtspiEvent *event, gpointer user_data)
115 int start_index, end_index;
119 gchar *role_name = atspi_accessible_get_role_name(event->source, NULL);
120 fprintf(stderr, "Event: %s: %d, obj: %p: role: %s\n",
121 event->type, event->detail1, event->source,
125 if (!strcmp(event->type, "object:scroll-start"))
127 DEBUG("Scrolling started");
128 tts_speak("Scrolling started", EINA_TRUE);
130 else if (!strcmp(event->type, "object:scroll-end"))
132 DEBUG("Scrolling finished");
133 tts_speak("Scrolling finished", EINA_FALSE);
134 get_realized_items_count((AtspiAccessible *)event->source, &start_index, &end_index);
135 _smart_notification_realized_items(start_index, end_index);
140 * @brief Initializer for smart notifications
144 void smart_notification_init(void)
146 DEBUG("Smart Notification init!");
148 AtspiEventListener *listener;
150 listener = atspi_event_listener_new(_scroll_event_cb, NULL, NULL);
151 atspi_event_listener_register(listener, "object:scroll-start", NULL);
152 atspi_event_listener_register(listener, "object:scroll-end", NULL);
154 haptic_module_init();
160 * @brief Smart notifications shutdown
163 void smart_notification_shutdown(void)
169 * @brief Smart notifications focus chain event handler
172 static void _smart_notification_focus_chain_end(void)
177 DEBUG(RED"Smart notification - FOCUS CHAIN END"RESET);
180 tone_player_start(TONE_TYPE_SUP_CONFIRM, SOUND_TYPE_MEDIA, 200, NULL);
184 * @brief Smart notifications realized items event handler
187 static void _smart_notification_realized_items(int start_idx, int end_idx)
192 if(start_idx == end_idx)
195 DEBUG(RED"Smart notification - Visible items notification"RESET);
199 snprintf(buf, sizeof(buf), _("IDS_REACHED_ITEMS_NOTIFICATION"), start_idx, end_idx);
201 tts_speak(strdup(buf), EINA_FALSE);