Java Code Examples for androidx.core.view.ViewCompat#replaceAccessibilityAction()

The following examples show how to use androidx.core.view.ViewCompat#replaceAccessibilityAction() . 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: AppBarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void addActionToExpand(
    CoordinatorLayout parent,
    @NonNull final T appBarLayout,
    @NonNull AccessibilityActionCompat action,
    final boolean expand) {
  ViewCompat.replaceAccessibilityAction(
      parent,
      action,
      null,
      new AccessibilityViewCommand() {
        @Override
        public boolean perform(@NonNull View view, @Nullable CommandArguments arguments) {
          appBarLayout.setExpanded(expand);
          return true;
        }
      });
}
 
Example 2
Source File: BottomSheetBehavior.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void addAccessibilityActionForState(
    V child, AccessibilityActionCompat action, final int state) {
  ViewCompat.replaceAccessibilityAction(
      child,
      action,
      null,
      new AccessibilityViewCommand() {
        @Override
        public boolean perform(@NonNull View view, @Nullable CommandArguments arguments) {
          setState(state);
          return true;
        }
      });
}
 
Example 3
Source File: SwipeDismissBehavior.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void updateAccessibilityActions(View child) {
  ViewCompat.removeAccessibilityAction(child, AccessibilityNodeInfoCompat.ACTION_DISMISS);
  if (canSwipeDismissView(child)) {
    ViewCompat.replaceAccessibilityAction(
        child,
        AccessibilityActionCompat.ACTION_DISMISS,
        null,
        new AccessibilityViewCommand() {
          @Override
          public boolean perform(@NonNull View view, @Nullable CommandArguments arguments) {
            if (canSwipeDismissView(view)) {
              final boolean isRtl =
                  ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL;
              boolean dismissToLeft =
                  (swipeDirection == SWIPE_DIRECTION_START_TO_END && isRtl)
                      || (swipeDirection == SWIPE_DIRECTION_END_TO_START && !isRtl);
              int offset = dismissToLeft ? -view.getWidth() : view.getWidth();
              ViewCompat.offsetLeftAndRight(view, offset);
              view.setAlpha(0f);
              if (listener != null) {
                listener.onDismiss(view);
              }
              return true;
            }
            return false;
          }
        });
  }
}
 
Example 4
Source File: BottomSheetBehavior.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addAccessibilityActionForState(
        V child, AccessibilityNodeInfoCompat.AccessibilityActionCompat action, final int state) {
    ViewCompat.replaceAccessibilityAction(
            child,
            action,
            null,
            (view, arguments) -> {
                setState(state);
                return true;
            });
}
 
Example 5
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void addAccessibilityScrollActions(
    final CoordinatorLayout coordinatorLayout,
    @NonNull final T appBarLayout,
    @NonNull final View scrollingView) {
  if (getTopBottomOffsetForScrollingSibling() != -appBarLayout.getTotalScrollRange()
      && scrollingView.canScrollVertically(1)) {
    // Add a collapsing action if the view can scroll up and the offset isn't the abl scroll
    // range. (This offset means the view is completely collapsed). Collapse to minimum height.
    addActionToExpand(coordinatorLayout, appBarLayout, ACTION_SCROLL_FORWARD, false);
  }
  // Don't add an expanding action if the sibling offset is 0, which would mean the abl is
  // completely expanded.
  if (getTopBottomOffsetForScrollingSibling() != 0) {
    if (scrollingView.canScrollVertically(-1)) {
      // Expanding action. If the view can scroll down, expand the app bar reflecting the logic
      // in onNestedPreScroll.
      final int dy = -appBarLayout.getDownNestedPreScrollRange();
      // Offset by non-zero.
      if (dy != 0) {
        ViewCompat.replaceAccessibilityAction(
            coordinatorLayout,
            ACTION_SCROLL_BACKWARD,
            null,
            new AccessibilityViewCommand() {
              @Override
              public boolean perform(@NonNull View view, @Nullable CommandArguments arguments) {
                onNestedPreScroll(
                    coordinatorLayout,
                    appBarLayout,
                    scrollingView,
                    0,
                    dy,
                    new int[] {0, 0},
                    ViewCompat.TYPE_NON_TOUCH);
                return true;
              }
            });
      }
    } else {
      // If the view can't scroll down, we are probably at the top of the scrolling content so
      // expand completely.
      addActionToExpand(coordinatorLayout, appBarLayout, ACTION_SCROLL_BACKWARD, true);
    }
  }
}