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)
49 case FOCUS_CHAIN_END_NOTIFICATION_EVENT:
50 _smart_notification_focus_chain_end();
52 case REALIZED_ITEMS_NOTIFICATION_EVENT:
53 _smart_notification_realized_items(start_index, end_index);
56 DEBUG("Gesture type %d not handled in switch", nt);
61 * @brief Used for getting first and last index of visible items
63 * @param scrollable_object AtspiAccessible object on which scroll was triggered
64 * @param start_index int first visible items index smart_notification_realized_items
65 * @param end_index int last visible items index used for smart_notification_realized_items
67 void get_realized_items_count(AtspiAccessible * scrollable_object, int *start_idx, int *end_idx)
71 AtspiAccessible *child_iter;
72 AtspiStateType state = ATSPI_STATE_SHOWING;
74 if (!scrollable_object) {
75 DEBUG("No scrollable object");
79 count_child = atspi_accessible_get_child_count(scrollable_object, NULL);
81 for (jdx = 0; jdx < count_child; jdx++) {
82 child_iter = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
86 AtspiStateSet *state_set = atspi_accessible_get_state_set(child_iter);
88 gboolean is_visible = atspi_state_set_contains(state_set, state);
91 DEBUG("Item with index %d is visible", jdx);
93 DEBUG("Item with index %d is NOT visible", jdx);
95 *end_idx = *start_idx + 8;
99 * @brief Scroll-start/Scroll-end event callback
101 * @param event AtspiEvent
102 * @param user_data UNUSED
105 static void _scroll_event_cb(AtspiEvent * event, gpointer user_data)
110 int start_index, end_index;
114 gchar *role_name = atspi_accessible_get_role_name(event->source, NULL);
115 fprintf(stderr, "Event: %s: %d, obj: %p: role: %s\n", event->type, event->detail1, event->source, role_name);
118 if (!strcmp(event->type, "object:scroll-start")) {
119 DEBUG("Scrolling started");
120 tts_speak(_("IDS_SCROLLING_STARTED"), EINA_TRUE);
121 } else if (!strcmp(event->type, "object:scroll-end")) {
122 DEBUG("Scrolling finished");
123 tts_speak(_("IDS_SCROLLING_FINISHED"), EINA_FALSE);
124 get_realized_items_count((AtspiAccessible *) event->source, &start_index, &end_index);
125 _smart_notification_realized_items(start_index, end_index);
130 * @brief Initializer for smart notifications
134 void smart_notification_init(void)
136 DEBUG("Smart Notification init!");
138 AtspiEventListener *listener;
140 listener = atspi_event_listener_new(_scroll_event_cb, NULL, NULL);
141 atspi_event_listener_register(listener, "object:scroll-start", NULL);
142 atspi_event_listener_register(listener, "object:scroll-end", NULL);
144 haptic_module_init();
150 * @brief Smart notifications shutdown
153 void smart_notification_shutdown(void)
159 * @brief Smart notifications focus chain event handler
162 static void _smart_notification_focus_chain_end(void)
167 DEBUG(RED "Smart notification - FOCUS CHAIN END" RESET);
170 tone_player_start(TONE_TYPE_SUP_CONFIRM, SOUND_TYPE_MEDIA, 200, NULL);
174 * @brief Smart notifications realized items event handler
177 static void _smart_notification_realized_items(int start_idx, int end_idx)
182 if (start_idx == end_idx)
185 DEBUG(RED "Smart notification - Visible items notification" RESET);
189 snprintf(buf, sizeof(buf), _("IDS_REACHED_ITEMS_NOTIFICATION"), start_idx, end_idx);
191 tts_speak(buf, EINA_FALSE);