Example usage for android.support.v4.view AccessibilityDelegateCompat AccessibilityDelegateCompat

List of usage examples for android.support.v4.view AccessibilityDelegateCompat AccessibilityDelegateCompat

Introduction

In this page you can find the example usage for android.support.v4.view AccessibilityDelegateCompat AccessibilityDelegateCompat.

Prototype

public AccessibilityDelegateCompat() 

Source Link

Document

Creates a new instance.

Usage

From source file:com.redinput.datetimepickercompat.date.YearPickerView.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override/*  www.j  a v a2 s. c o  m*/
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
                event.setFromIndex(0);
            }
        }

    });
}

From source file:com.android.datetimepicker.time.RadialPickerLayout.java

private void installAccessibilityDelegate() {
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        /**/*w  w w. ja  v a 2  s .  c om*/
         * Necessary for accessibility, to ensure we support "scrolling" forward and backward
         * in the circle.
         */
        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    });
}

From source file:com.redinput.datetimepickercompat.date.DayPickerView.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override//  w  w  w  .  j av a2  s.  com
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            event.setItemCount(-1);
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (action != AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD
                    && action != AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) {
                return super.performAccessibilityAction(host, action, args);
            }

            // Figure out what month is showing.
            int firstVisiblePosition = getFirstVisiblePosition();
            int month = firstVisiblePosition % 12;
            int year = firstVisiblePosition / 12 + mController.getMinYear();
            CalendarDay day = new CalendarDay(year, month, 1);

            // Scroll either forward or backward one month.
            if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) {
                day.month++;
                if (day.month == 12) {
                    day.month = 0;
                    day.year++;
                }
            } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) {
                View firstVisibleView = getChildAt(0);
                // If the view is fully visible, jump one month back. Otherwise, we'll just jump
                // to the first day of first visible month.
                if (firstVisibleView != null && firstVisibleView.getTop() >= -1) {
                    // There's an off-by-one somewhere, so the top of the first visible item
                    // will
                    // actually be -1 when it's at the exact top.
                    day.month--;
                    if (day.month == -1) {
                        day.month = 11;
                        day.year--;
                    }
                }
            }

            // Go to that month.
            Utils.tryAccessibilityAnnounce(host, getMonthAndYearString(day));
            goTo(day, true, false, true);
            mPerformingScroll = true;
            return true;
        }
    });
}

From source file:com.redinput.datetimepickercompat.time.RadialPickerLayout.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override//from  www  .j ava  2  s  .  co m
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
            info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
        }

        @Override
        public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
                // Clear the event's current text so that only the current time will be spoken.
                event.getText().clear();
                Time time = new Time();
                time.hour = getHours();
                time.minute = getMinutes();
                long millis = time.normalize(true);
                int flags = DateUtils.FORMAT_SHOW_TIME;
                if (mIs24HourMode) {
                    flags |= DateUtils.FORMAT_24HOUR;
                }
                String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
                event.getText().add(timeString);
                return true;
            }

            return super.dispatchPopulateAccessibilityEvent(host, event);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            if (super.performAccessibilityAction(host, action, args)) {
                return true;
            }

            int changeMultiplier = 0;
            if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) {
                changeMultiplier = 1;
            } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) {
                changeMultiplier = -1;
            }
            if (changeMultiplier != 0) {
                int value = getCurrentlyShowingValue();
                int stepSize = 0;
                int currentItemShowing = getCurrentItemShowing();
                if (currentItemShowing == HOUR_INDEX) {
                    stepSize = HOUR_VALUE_TO_DEGREES_STEP_SIZE;
                    value %= 12;
                } else if (currentItemShowing == MINUTE_INDEX) {
                    stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE;
                }

                int degrees = value * stepSize;
                degrees = snapOnly30s(degrees, changeMultiplier);
                value = degrees / stepSize;
                int maxValue = 0;
                int minValue = 0;
                if (currentItemShowing == HOUR_INDEX) {
                    if (mIs24HourMode) {
                        maxValue = 23;
                    } else {
                        maxValue = 12;
                        minValue = 1;
                    }
                } else {
                    maxValue = 55;
                }
                if (value > maxValue) {
                    // If we scrolled forward past the highest number, wrap around to the
                    // lowest.
                    value = minValue;
                } else if (value < minValue) {
                    // If we scrolled backward past the lowest number, wrap around to the
                    // highest.
                    value = maxValue;
                }
                setItem(currentItemShowing, value);
                mListener.onValueSelected(currentItemShowing, value, false);
                return true;
            }

            return false;
        }
    });
}