Exemplo n.º 1
0
        public void SetAnnouncement(string text)
        {
            AccessibilityManager manager = (AccessibilityManager)Android.App.Application.Context.GetSystemService(Android.App.Application.AccessibilityService);

            if (!(manager.IsEnabled || manager.IsTouchExplorationEnabled))
            {
                return;
            }

            // Sends the accessibility event to announce.
            AccessibilityEvent e = AccessibilityEvent.Obtain();

            e.EventType = EventTypes.Announcement;
            e.Text.Add(new Java.Lang.String(text));
            manager.SendAccessibilityEvent(e);
        }
        static void PlatformAnnounce(string text)
        {
            var manager      = AApplication.Context.GetSystemService(AContext.AccessibilityService) as AccessibilityManager;
            var announcement = AccessibilityEvent.Obtain();

            if (manager == null || announcement == null)
            {
                return;
            }

            if (!(manager.IsEnabled || manager.IsTouchExplorationEnabled))
            {
                return;
            }

            announcement.EventType = EventTypes.Announcement;
            announcement.Text?.Add(new Java.Lang.String(text));
            manager.SendAccessibilityEvent(announcement);
        }
Exemplo n.º 3
0
        public static void AnnounceForAccessibilityCompat(Context context, String text)
        {
            if ((int)Build.VERSION.SdkInt >= 4)
            {
                AccessibilityManager accessibilityManager = null;
                if (null != context)
                {
                    accessibilityManager = (AccessibilityManager)context.GetSystemService(Context.AccessibilityService);
                }
                if (null == accessibilityManager || !accessibilityManager.IsEnabled)
                {
                    return;
                }

                // Prior to SDK 16, announcements could only be made through FOCUSED
                // events. Jelly Bean (SDK 16) added support for speaking text verbatim
                // using the ANNOUNCEMENT event type.
                EventTypes eventType;
                if ((int)Build.VERSION.SdkInt < 16)
                {
                    eventType = EventTypes.ViewFocused;
                }
                else
                {
                    eventType = EventTypes.Announcement;
                }

                // Construct an accessibility event with the minimum recommended
                // attributes. An event without a class name or package may be dropped.
                AccessibilityEvent ev = AccessibilityEvent.Obtain(eventType);
                var textProxy         = new Java.Lang.String(text);
                ev.Text.Add(textProxy);
                ev.ClassName   = _instance.GetType().ToString();
                ev.PackageName = context.PackageName;

                // Sends the event directly through the accessibility manager. If your
                // application only targets SDK 14+, you should just call
                // getParent().requestSendAccessibilityEvent(this, event);
                accessibilityManager.SendAccessibilityEvent(ev);
            }
        }
Exemplo n.º 4
0
        public void ScreenReaderAnnouncement(string notification)
        {
            if ((MainActivity.accessibilityManager != null) &&
                MainActivity.accessibilityManager.IsEnabled)
            {
                ICharSequence charSeqNotification = new Java.Lang.String(notification);

                AccessibilityEvent e = AccessibilityEvent.Obtain();

                e.EventType = (EventTypes)0x00004000; // This is the Android value.

                e.Text.Add(charSeqNotification);

                // NOTE: Announcements don't seem to interfer with other
                // default announcements. Eg when game restarted, announcement on
                // where focus is afterwards still gets announced. And note that
                // focus remains on card being moved from a delat card pile, and
                // so no announcement there gets announced by default anyway.

                MainActivity.accessibilityManager.SendAccessibilityEvent(e);
            }
        }