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

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_BACKWARD . 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: RadialTimePickerView.java    From android_9.0.0_r45 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 2
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
private void sendScrollAccessibilityEvent() {
    AccessibilityManager am =
            (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (am.isEnabled()) {
        AccessibilityEvent ev =
                AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
        ev.setItemCount(getChildCount());
        ev.setFromIndex(mCurrentPage);
        ev.setToIndex(getNextPage());

        final int action;
        if (getNextPage() >= mCurrentPage) {
            action = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
        } else {
            action = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
        }

        ev.setAction(action);
        sendAccessibilityEventUnchecked(ev);
    }
}
 
Example 3
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 4
Source File: PagedView.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
private void sendScrollAccessibilityEvent() {
    AccessibilityManager am =
            (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (am.isEnabled()) {
        AccessibilityEvent ev =
                AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_SCROLLED);
        ev.setItemCount(getChildCount());
        ev.setFromIndex(mCurrentPage);
        ev.setToIndex(getNextPage());

        final int action;
        if (getNextPage() >= mCurrentPage) {
            action = AccessibilityNodeInfo.ACTION_SCROLL_FORWARD;
        } else {
            action = AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD;
        }

        ev.setAction(action);
        sendAccessibilityEventUnchecked(ev);
    }
}
 
Example 5
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 6
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 7
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 8
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 9
Source File: RadialPickerLayout.java    From date_picker_converter 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.
 */
@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;
}
 
Example 10
Source File: RadialPickerLayout.java    From MaterialDateTimePicker 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.
 */
@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;
}
 
Example 11
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 12
Source File: ViewHierarchyElementAndroid.java    From Accessibility-Test-Framework-for-Android with Apache License 2.0 4 votes vote down vote up
Builder(int id, @Nullable ViewHierarchyElementAndroid parent, AccessibilityNodeInfo fromInfo) {
  // Bookkeeping
  this.id = id;
  this.parentId = (parent != null) ? parent.getId() : null;

  // API 18+ properties
  this.resourceName = AT_18 ? fromInfo.getViewIdResourceName() : null;
  this.editable = AT_18 ? fromInfo.isEditable() : null;

  // API 16+ properties
  this.visibleToUser = AT_16 ? fromInfo.isVisibleToUser() : null;

  // API 21+ properties
  if (AT_21) {
    ImmutableList.Builder<ViewHierarchyActionAndroid> actionBuilder =
        new ImmutableList.Builder<>();
    actionBuilder.addAll(
        Lists.transform(
            fromInfo.getActionList(),
            action -> ViewHierarchyActionAndroid.newBuilder(action).build()));
    this.actionList = actionBuilder.build();
  }

  // API 24+ properties
  this.drawingOrder = AT_24 ? fromInfo.getDrawingOrder() : null;

  // API 29+ properties
  this.hasTouchDelegate = AT_29 ? (fromInfo.getTouchDelegateInfo() != null) : null;

  // Base properties
  this.className = fromInfo.getClassName();
  this.packageName = fromInfo.getPackageName();
  this.accessibilityClassName = fromInfo.getClassName();
  this.contentDescription = SpannableStringAndroid.valueOf(fromInfo.getContentDescription());
  this.text = SpannableStringAndroid.valueOf(fromInfo.getText());

  this.importantForAccessibility = true;
  this.clickable = fromInfo.isClickable();
  this.longClickable = fromInfo.isLongClickable();
  this.focusable = fromInfo.isFocusable();
  this.scrollable = fromInfo.isScrollable();
  this.canScrollForward =
      ((fromInfo.getActions() & AccessibilityNodeInfo.ACTION_SCROLL_FORWARD) != 0);
  this.canScrollBackward =
      ((fromInfo.getActions() & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0);
  this.checkable = fromInfo.isCheckable();
  this.checked = fromInfo.isChecked();
  this.touchDelegateBounds = new ArrayList<>(); // Populated after construction
  android.graphics.Rect tempRect = new android.graphics.Rect();
  fromInfo.getBoundsInScreen(tempRect);
  this.boundsInScreen = new Rect(tempRect.left, tempRect.top, tempRect.right, tempRect.bottom);
  this.nonclippedHeight = null;
  this.nonclippedWidth = null;
  this.textSize = null;
  this.textColor = null;
  this.backgroundDrawableColor = null;
  this.typefaceStyle = null;
  this.enabled = fromInfo.isEnabled();
}
 
Example 13
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 14
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 15
Source File: RadialPickerLayout.java    From MaterialDateRangePicker 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 16
Source File: RadialPickerLayout.java    From StyleableDateTimePicker with MIT License 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 17
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 18
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 19
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 20
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;
}