Java Code Examples for android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_FORWARD

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_FORWARD . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PagedView.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }
    switch (action) {
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
            if (getCurrentPage() < getPageCount() - 1) {
                scrollRight();
                return true;
            }
        } break;
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
            if (getCurrentPage() > 0) {
                scrollLeft();
                return true;
            }
        } break;
    }
    return false;
}
 
Example 2
Source File: RadialTimePickerView.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle arguments) {
    if (super.performAccessibilityAction(host, action, arguments)) {
        return true;
    }

    switch (action) {
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
            adjustPicker(1);
            return true;
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
            adjustPicker(-1);
            return true;
    }

    return false;
}
 
Example 3
Source File: StackView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** @hide */
@Override
public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
    if (super.performAccessibilityActionInternal(action, arguments)) {
        return true;
    }
    if (!isEnabled()) {
        return false;
    }
    switch (action) {
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
            if (getDisplayedChild() < getChildCount() - 1) {
                showNext();
                return true;
            }
        } return false;
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
            if (getDisplayedChild() > 0) {
                showPrevious();
                return true;
            }
        } return false;
    }
    return false;
}
 
Example 4
Source File: SdkCenteredViewPager.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args)
{
    if ( super.performAccessibilityAction( host, action, args ) )
    {
        return true;
    }
    switch ( action )
    {
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
        {
            if ( canScrollHorizontally( 1 ) )
            {
                setCurrentItem( mCurItem + 1 );
                return true;
            }
        }
        return false;
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
        {
            if ( canScrollHorizontally( -1 ) )
            {
                setCurrentItem( mCurItem - 1 );
                return true;
            }
        }
        return false;
    }
    return false;
}
 
Example 5
Source File: MultiSlider.java    From MultiSlider with Apache License 2.0 5 votes vote down vote up
@Override
public boolean performAction(int virtualViewId, int action, Bundle arguments) {
    if (virtualViewId == View.NO_ID) {
        //do nothing ..  for now
        return false;
    } else {
        if (virtualViewId >= mThumbs.size()) return false;
        Thumb thumb = mThumbs.get(virtualViewId);
        if (thumb == null) return false;

        switch (action) {
            case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
                thumb.setValue(thumb.value + getStep());
                return true;

            case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
                thumb.setValue(thumb.value - getStep());
                return true;

            case ACT_SET_PROGRESS:
                thumb.setValue(arguments.getInt("value"));
                return true;
        }
    }

    return false;
}
 
Example 6
Source File: SdkCenteredViewPager.java    From Android-SDK-Demo with MIT License 5 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args)
{
    if ( super.performAccessibilityAction( host, action, args ) )
    {
        return true;
    }
    switch ( action )
    {
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
        {
            if ( canScrollHorizontally( 1 ) )
            {
                setCurrentItem( mCurItem + 1 );
                return true;
            }
        }
        return false;
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
        {
            if ( canScrollHorizontally( -1 ) )
            {
                setCurrentItem( mCurItem - 1 );
                return true;
            }
        }
        return false;
    }
    return false;
}
 
Example 7
Source File: DefaultNavigationMode.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the specified node is suitable for autoscrolling and will
 * try to scroll it if it is.
 * Note we might have an issue here when more than one node is on the line
 * or not the whole list item is visible.
 */
private boolean autoScrollItem(AccessibilityNodeInfoCompat node,
        int scrollDirection) {
    int edgeDirection =
            (scrollDirection == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD)
                ? 1 : -1;
    return AccessibilityNodeInfoUtils.isAutoScrollEdgeListItem(
                    mAccessibilityService, node, edgeDirection)
            && attemptScrollAction(scrollDirection);
}
 
Example 8
Source File: RadialPickerLayout.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }

    int changeMultiplier = 0;
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        changeMultiplier = 1;
    } else if (action == AccessibilityNodeInfo.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;
}
 
Example 9
Source File: RadialPickerLayout.java    From Android-SwitchDateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }

    int changeMultiplier = 0;
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        changeMultiplier = 1;
    } else if (action == AccessibilityNodeInfo.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;
}
 
Example 10
Source File: RadialPickerLayout.java    From Blackbulb with GNU General Public License v3.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 */
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }

    int changeMultiplier = 0;
    int forward;
    int backward;
    if (Build.VERSION.SDK_INT >= 16) {
        forward = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
        backward = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
    } else {
        forward = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
        backward = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
    }
    if (action == forward) {
        changeMultiplier = 1;
    } else if (action == 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;
        } else if (currentItemShowing == SECOND_INDEX) {
            stepSize = SECOND_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;
        }

        Timepoint newSelection;
        switch(currentItemShowing) {
            case HOUR_INDEX:
                newSelection = new Timepoint(
                        value,
                        mCurrentTime.getMinute(),
                        mCurrentTime.getSecond()
                );
                break;
            case MINUTE_INDEX:
                newSelection = new Timepoint(
                        mCurrentTime.getHour(),
                        value,
                        mCurrentTime.getSecond()
                );
                break;
            case SECOND_INDEX:
                newSelection = new Timepoint(
                        mCurrentTime.getHour(),
                        mCurrentTime.getMinute(),
                        value
                );
                break;
            default:
                newSelection = mCurrentTime;
        }

        setItem(currentItemShowing, newSelection);
        mListener.onValueSelected(newSelection);
        return true;
    }

    return false;
}
 
Example 11
Source File: DayPickerView.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // 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 == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    mPerformingScroll = true;
    return true;
}
 
Example 12
Source File: PagingDayPickerView.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // Figure out what month is showing.
    int firstVisiblePosition = getPagerPosition();
    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 == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    return true;
}
 
Example 13
Source File: RadialPickerLayout.java    From AlarmOn with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }

    int changeMultiplier = 0;
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        changeMultiplier = 1;
    } else if (action == AccessibilityNodeInfo.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;
        } else if (currentItemShowing == SECOND_INDEX) {
            stepSize = SECOND_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;
        }

        Timepoint newSelection;
        switch(currentItemShowing) {
            case HOUR_INDEX:
                newSelection = new Timepoint(
                        value,
                        mCurrentTime.getMinute(),
                        mCurrentTime.getSecond()
                );
                break;
            case MINUTE_INDEX:
                newSelection = new Timepoint(
                        mCurrentTime.getHour(),
                        value,
                        mCurrentTime.getSecond()
                );
                break;
            case SECOND_INDEX:
                newSelection = new Timepoint(
                        mCurrentTime.getHour(),
                        mCurrentTime.getMinute(),
                        value
                );
                break;
            default:
                newSelection = mCurrentTime;
        }

        setItem(currentItemShowing, newSelection);
        mListener.onValueSelected(newSelection);
        return true;
    }

    return false;
}
 
Example 14
Source File: DayPickerView.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // 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 == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    mPerformingScroll = true;
    return true;
}
 
Example 15
Source File: DayPickerView.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // Figure out what month is showing.
    int firstVisiblePosition = getFirstVisiblePosition();
    int minMonth = mController.getStartDate().get(Calendar.MONTH);
    int month = (firstVisiblePosition + minMonth) % MonthAdapter.MONTHS_IN_YEAR;
    int year = (firstVisiblePosition + minMonth) / MonthAdapter.MONTHS_IN_YEAR + mController.getMinYear();
    MonthAdapter.CalendarDay day = new MonthAdapter.CalendarDay(year, month, 1);

    // Scroll either forward or backward one month.
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    mPerformingScroll = true;
    return true;
}
 
Example 16
Source File: DayPickerView.java    From MaterialDateRangePicker with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

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

    // Scroll either forward or backward one month.
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    mPerformingScroll = true;
    return true;
}
 
Example 17
Source File: DayPickerView.java    From AlarmOn with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // Figure out what month is showing.
    int firstVisiblePosition = getFirstVisiblePosition();
    int minMonth = mController.getStartDate().get(Calendar.MONTH);
    int month = (firstVisiblePosition + minMonth) % MonthAdapter.MONTHS_IN_YEAR;
    int year = (firstVisiblePosition + minMonth) / MonthAdapter.MONTHS_IN_YEAR + mController.getMinYear();
    MonthAdapter.CalendarDay day = new MonthAdapter.CalendarDay(year, month, 1);

    // Scroll either forward or backward one month.
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    mPerformingScroll = true;
    return true;
}
 
Example 18
Source File: DayPickerView.java    From StyleableDateTimePicker with MIT License 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, announce the newly scrolled-to month.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (action != AccessibilityNodeInfo.ACTION_SCROLL_FORWARD &&
            action != AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
        return super.performAccessibilityAction(action, arguments);
    }

    // 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 == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        day.month++;
        if (day.month == 12) {
            day.month = 0;
            day.year++;
        }
    } else if (action == AccessibilityNodeInfo.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(this, getMonthAndYearString(day));
    goTo(day, true, false, true);
    mPerformingScroll = true;
    return true;
}
 
Example 19
Source File: AbsSeekBar.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/** @hide */
@Override
public boolean performAccessibilityActionInternal(int action, Bundle arguments) {
    if (super.performAccessibilityActionInternal(action, arguments)) {
        return true;
    }

    if (!isEnabled()) {
        return false;
    }

    switch (action) {
        case R.id.accessibilityActionSetProgress: {
            if (!canUserSetProgress()) {
                return false;
            }
            if (arguments == null || !arguments.containsKey(
                    AccessibilityNodeInfo.ACTION_ARGUMENT_PROGRESS_VALUE)) {
                return false;
            }
            float value = arguments.getFloat(
                    AccessibilityNodeInfo.ACTION_ARGUMENT_PROGRESS_VALUE);
            return setProgressInternal((int) value, true, true);
        }
        case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
        case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
            if (!canUserSetProgress()) {
                return false;
            }
            int range = getMax() - getMin();
            int increment = Math.max(1, Math.round((float) range / 20));
            if (action == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
                increment = -increment;
            }

            // Let progress bar handle clamping values.
            if (setProgressInternal(getProgress() + increment, true, true)) {
                onKeyChange();
                return true;
            }
            return false;
        }
    }
    return false;
}
 
Example 20
Source File: RadialPickerLayout.java    From Conquer with Apache License 2.0 4 votes vote down vote up
/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 */
@SuppressLint("NewApi")
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }

    int changeMultiplier = 0;
    if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) {
        changeMultiplier = 1;
    } else if (action == AccessibilityNodeInfo.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;
}