Example usage for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD

List of usage examples for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD.

Prototype

int ACTION_SCROLL_BACKWARD

To view the source code for android.view.accessibility AccessibilityNodeInfo ACTION_SCROLL_BACKWARD.

Click Source Link

Document

Action to scroll the node content backward.

Usage

From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java

/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 *///  w ww. j a  va  2 s. c om
@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;
}

From source file:com.customdatepicker.time.RadialPickerLayout.java

/**
 * When scroll forward/backward events are received, jump the time to the higher/lower
 * discrete, visible value on the circle.
 *///from   www . ja va  2  s .  co  m
@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 = AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD;
        backward = AccessibilityNodeInfoCompat.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;
}

From source file:android.widget.Gallery.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName(Gallery.class.getName());
    info.setScrollable(mItemCount > 1);
    if (isEnabled()) {
        if (mItemCount > 0 && mSelectedPosition < mItemCount - 1) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        }/*w  ww. jav  a2  s .  c o  m*/
        if (isEnabled() && mItemCount > 0 && mSelectedPosition > 0) {
            info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
        }
    }
}

From source file:com.common.widget.hzlib.AbsListView.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        info.setClassName(AbsListView.class.getName());
    }/*w  w  w .j  a  v  a 2  s.co m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (isEnabled()) {
            if (getFirstVisiblePosition() > 0) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
            }
            if (getLastVisiblePosition() < getCount() - 1) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
        }
    }
}

From source file:android.widget.Gallery.java

@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }/*from  www .  ja  va2  s  .  c  om*/
    switch (action) {
    case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
        if (isEnabled() && mItemCount > 0 && mSelectedPosition < mItemCount - 1) {
            final int currentChildIndex = mSelectedPosition - mFirstPosition;
            return scrollToChild(currentChildIndex + 1);
        }
    }
        return false;
    case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
        if (isEnabled() && mItemCount > 0 && mSelectedPosition > 0) {
            final int currentChildIndex = mSelectedPosition - mFirstPosition;
            return scrollToChild(currentChildIndex - 1);
        }
    }
        return false;
    }
    return false;
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        info.setClassName(AbsHorizontalListView.class.getName());
    }//from   w w w . j  a  v  a2s  . c o  m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (isEnabled()) {
            if (getFirstVisiblePosition() > 0) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
            }
            if (getLastVisiblePosition() < getCount() - 1) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
        }
    }
}

From source file:com.appunite.list.AbsHorizontalListView.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override//from w ww.j  a v  a 2 s  . c o  m
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }
    switch (action) {
    case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
        if (isEnabled() && getLastVisiblePosition() < getCount() - 1) {
            final int viewportWidth = getWidth() - mListPadding.left - mListPadding.right;
            smoothScrollBy(viewportWidth, PositionScroller.SCROLL_DURATION);
            return true;
        }
    }
        return false;
    case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
        if (isEnabled() && mFirstPosition > 0) {
            final int viewportWidth = getWidth() - mListPadding.left - mListPadding.right;
            smoothScrollBy(-viewportWidth, PositionScroller.SCROLL_DURATION);
            return true;
        }
    }
        return false;
    }
    return false;
}

From source file:com.liu.hz.view.AbsHorizontalListView.java

@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        info.setClassName(AbsHorizontalListView.class.getName());
    }/*w ww  . jav a  2  s . co m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (isEnabled()) {
            if (getFirstVisiblePosition() > 0) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
            }
            if (getLastVisiblePosition() < getCount() - 1) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
        }
    }
}

From source file:com.appunite.list.AbsListView.java

@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        info.setClassName(AbsListView.class.getName());
    }/*  w ww . j  a v a 2s .c o m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (isEnabled()) {
            if (getFirstVisiblePosition() > 0) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
            }
            if (getLastVisiblePosition() < getCount() - 1) {
                info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
            }
        }
    }
}

From source file:com.appunite.list.AbsListView.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override/*from w  w w .  jav  a 2 s.c  o m*/
public boolean performAccessibilityAction(int action, Bundle arguments) {
    if (super.performAccessibilityAction(action, arguments)) {
        return true;
    }
    switch (action) {
    case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
        if (isEnabled() && getLastVisiblePosition() < getCount() - 1) {
            final int viewportHeight = getHeight() - mListPadding.top - mListPadding.bottom;
            smoothScrollBy(viewportHeight, PositionScroller.SCROLL_DURATION);
            return true;
        }
    }
        return false;
    case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
        if (isEnabled() && mFirstPosition > 0) {
            final int viewportHeight = getHeight() - mListPadding.top - mListPadding.bottom;
            smoothScrollBy(-viewportHeight, PositionScroller.SCROLL_DURATION);
            return true;
        }
    }
        return false;
    }
    return false;
}