androidx.core.view.AccessibilityDelegateCompat Java Examples

The following examples show how to use androidx.core.view.AccessibilityDelegateCompat. 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: EventDispatcherUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static boolean dispatchDispatchPopulateAccessibilityEvent(
    EventHandler<DispatchPopulateAccessibilityEventEvent> eventHandler,
    View host,
    AccessibilityEvent event,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sDispatchPopulateAccessibilityEventEvent == null) {
    sDispatchPopulateAccessibilityEventEvent = new DispatchPopulateAccessibilityEventEvent();
  }

  sDispatchPopulateAccessibilityEventEvent.host = host;
  sDispatchPopulateAccessibilityEventEvent.event = event;
  sDispatchPopulateAccessibilityEventEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  final Object returnValue =
      eventDispatcher.dispatchOnEvent(eventHandler, sDispatchPopulateAccessibilityEventEvent);

  sDispatchPopulateAccessibilityEventEvent.host = null;
  sDispatchPopulateAccessibilityEventEvent.event = null;
  sDispatchPopulateAccessibilityEventEvent.superDelegate = null;

  return returnValue != null && (boolean) returnValue;
}
 
Example #2
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static void dispatchOnInitializeAccessibilityEvent(
    EventHandler<OnInitializeAccessibilityEventEvent> eventHandler,
    View host,
    AccessibilityEvent event,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sOnInitializeAccessibilityEventEvent == null) {
    sOnInitializeAccessibilityEventEvent = new OnInitializeAccessibilityEventEvent();
  }

  sOnInitializeAccessibilityEventEvent.host = host;
  sOnInitializeAccessibilityEventEvent.event = event;
  sOnInitializeAccessibilityEventEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  eventDispatcher.dispatchOnEvent(eventHandler, sOnInitializeAccessibilityEventEvent);

  sOnInitializeAccessibilityEventEvent.host = null;
  sOnInitializeAccessibilityEventEvent.event = null;
  sOnInitializeAccessibilityEventEvent.superDelegate = null;
}
 
Example #3
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static void dispatchOnInitializeAccessibilityNodeInfoEvent(
    EventHandler<OnInitializeAccessibilityNodeInfoEvent> eventHandler,
    View host,
    AccessibilityNodeInfoCompat info,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sOnInitializeAccessibilityNodeInfoEvent == null) {
    sOnInitializeAccessibilityNodeInfoEvent = new OnInitializeAccessibilityNodeInfoEvent();
  }

  sOnInitializeAccessibilityNodeInfoEvent.host = host;
  sOnInitializeAccessibilityNodeInfoEvent.info = info;
  sOnInitializeAccessibilityNodeInfoEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  eventDispatcher.dispatchOnEvent(eventHandler, sOnInitializeAccessibilityNodeInfoEvent);

  sOnInitializeAccessibilityNodeInfoEvent.host = null;
  sOnInitializeAccessibilityNodeInfoEvent.info = null;
  sOnInitializeAccessibilityNodeInfoEvent.superDelegate = null;
}
 
Example #4
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static void dispatchOnPopulateAccessibilityEvent(
    EventHandler<OnPopulateAccessibilityEventEvent> eventHandler,
    View host,
    AccessibilityEvent event,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sOnPopulateAccessibilityEventEvent == null) {
    sOnPopulateAccessibilityEventEvent = new OnPopulateAccessibilityEventEvent();
  }

  sOnPopulateAccessibilityEventEvent.host = host;
  sOnPopulateAccessibilityEventEvent.event = event;
  sOnPopulateAccessibilityEventEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  eventDispatcher.dispatchOnEvent(eventHandler, sOnPopulateAccessibilityEventEvent);

  sOnPopulateAccessibilityEventEvent.host = null;
  sOnPopulateAccessibilityEventEvent.event = null;
  sOnPopulateAccessibilityEventEvent.superDelegate = null;
}
 
Example #5
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static void dispatchSendAccessibilityEvent(
    EventHandler<SendAccessibilityEventEvent> eventHandler,
    View host,
    int eventType,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sSendAccessibilityEventEvent == null) {
    sSendAccessibilityEventEvent = new SendAccessibilityEventEvent();
  }

  sSendAccessibilityEventEvent.host = host;
  sSendAccessibilityEventEvent.eventType = eventType;
  sSendAccessibilityEventEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  eventDispatcher.dispatchOnEvent(eventHandler, sSendAccessibilityEventEvent);

  sSendAccessibilityEventEvent.host = null;
  sSendAccessibilityEventEvent.eventType = 0;
  sSendAccessibilityEventEvent.superDelegate = null;
}
 
Example #6
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static void dispatchSendAccessibilityEventUnchecked(
    EventHandler<SendAccessibilityEventUncheckedEvent> eventHandler,
    View host,
    AccessibilityEvent event,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sSendAccessibilityEventUncheckedEvent == null) {
    sSendAccessibilityEventUncheckedEvent = new SendAccessibilityEventUncheckedEvent();
  }

  sSendAccessibilityEventUncheckedEvent.host = host;
  sSendAccessibilityEventUncheckedEvent.event = event;
  sSendAccessibilityEventUncheckedEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  eventDispatcher.dispatchOnEvent(eventHandler, sSendAccessibilityEventUncheckedEvent);

  sSendAccessibilityEventUncheckedEvent.host = null;
  sSendAccessibilityEventUncheckedEvent.event = null;
  sSendAccessibilityEventUncheckedEvent.superDelegate = null;
}
 
Example #7
Source File: MaterialCalendarGridView.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public MaterialCalendarGridView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  if (MaterialDatePicker.isFullscreen(getContext())) {
    setNextFocusLeftId(R.id.cancel_button);
    setNextFocusRightId(R.id.confirm_button);
  }
  ViewCompat.setAccessibilityDelegate(
      this,
      new AccessibilityDelegateCompat() {
        @Override
        public void onInitializeAccessibilityNodeInfo(
            View view, @NonNull AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
          super.onInitializeAccessibilityNodeInfo(view, accessibilityNodeInfoCompat);
          // Stop announcing of row/col information in favor of internationalized day information.
          accessibilityNodeInfoCompat.setCollectionInfo(null);
        }
      });
}
 
Example #8
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
static boolean dispatchOnRequestSendAccessibilityEvent(
    EventHandler<OnRequestSendAccessibilityEventEvent> eventHandler,
    ViewGroup host,
    View child,
    AccessibilityEvent event,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sOnRequestSendAccessibilityEventEvent == null) {
    sOnRequestSendAccessibilityEventEvent = new OnRequestSendAccessibilityEventEvent();
  }

  sOnRequestSendAccessibilityEventEvent.host = host;
  sOnRequestSendAccessibilityEventEvent.child = child;
  sOnRequestSendAccessibilityEventEvent.event = event;
  sOnRequestSendAccessibilityEventEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();

  final Object returnValue =
      eventDispatcher.dispatchOnEvent(eventHandler, sOnRequestSendAccessibilityEventEvent);

  sOnRequestSendAccessibilityEventEvent.host = null;
  sOnRequestSendAccessibilityEventEvent.child = null;
  sOnRequestSendAccessibilityEventEvent.event = null;
  sOnRequestSendAccessibilityEventEvent.superDelegate = null;

  return returnValue != null && (boolean) returnValue;
}
 
Example #9
Source File: EventDispatcherUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
static boolean dispatchPerformAccessibilityActionEvent(
    EventHandler<PerformAccessibilityActionEvent> eventHandler,
    View host,
    int action,
    Bundle args,
    AccessibilityDelegateCompat superDelegate) {
  assertMainThread();

  if (sPerformAccessibilityActionEvent == null) {
    sPerformAccessibilityActionEvent = new PerformAccessibilityActionEvent();
  }

  sPerformAccessibilityActionEvent.host = host;
  sPerformAccessibilityActionEvent.action = action;
  sPerformAccessibilityActionEvent.args = args;
  sPerformAccessibilityActionEvent.superDelegate = superDelegate;

  final EventDispatcher eventDispatcher = eventHandler.mHasEventDispatcher.getEventDispatcher();
  final Object returnValue =
      eventDispatcher.dispatchOnEvent(eventHandler, sPerformAccessibilityActionEvent);

  sPerformAccessibilityActionEvent.host = null;
  sPerformAccessibilityActionEvent.action = 0;
  sPerformAccessibilityActionEvent.args = null;
  sPerformAccessibilityActionEvent.superDelegate = null;

  return returnValue != null && (boolean) returnValue;
}
 
Example #10
Source File: ChipTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasCustomAccessibilityDelegate() {
  chip.setCloseIconResource(R.drawable.ic_mtrl_chip_close_circle);
  chip.setCloseIconVisible(true);
  chip.setOnCloseIconClickListener(
      new OnClickListener() {
        @Override
        public void onClick(View v) {
          /* Do something */
        }
      });
  AccessibilityDelegateCompat accessibilityDelegate = ViewCompat.getAccessibilityDelegate(chip);
  assertThat(accessibilityDelegate).isNotNull();
}
 
Example #11
Source File: MaterialButtonToggleGroup.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
/**
 * This override prohibits Views other than {@link MaterialButton} to be added. It also makes
 * updates to the add button shape and margins.
 */
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
  if (!(child instanceof MaterialButton)) {
    Log.e(LOG_TAG, "Child views must be of type MaterialButton.");
    return;
  }

  super.addView(child, index, params);
  MaterialButton buttonChild = (MaterialButton) child;
  setGeneratedIdIfNeeded(buttonChild);
  // Sets sensible default values and an internal checked change listener for this child
  setupButtonChild(buttonChild);

  // Reorders children if a checked child was added to this layout
  if (buttonChild.isChecked()) {
    updateCheckedStates(buttonChild.getId(), true);
    setCheckedId(buttonChild.getId());
  }

  // Saves original corner data
  ShapeAppearanceModel shapeAppearanceModel = buttonChild.getShapeAppearanceModel();
  originalCornerData.add(
      new CornerData(
          shapeAppearanceModel.getTopLeftCornerSize(),
          shapeAppearanceModel.getBottomLeftCornerSize(),
          shapeAppearanceModel.getTopRightCornerSize(),
          shapeAppearanceModel.getBottomRightCornerSize()));

  ViewCompat.setAccessibilityDelegate(
      buttonChild,
      new AccessibilityDelegateCompat() {
        @Override
        public void onInitializeAccessibilityNodeInfo(
            View host, @NonNull AccessibilityNodeInfoCompat info) {
          super.onInitializeAccessibilityNodeInfo(host, info);
          info.setCollectionItemInfo(
              CollectionItemInfoCompat.obtain(
                  /* rowIndex= */ 0,
                  /* rowSpan= */ 1,
                  /* columnIndex= */ getIndexWithinVisibleButtons(host),
                  /* columnSpan= */ 1,
                  /* heading= */ false,
                  /* selected= */ ((MaterialButton) host).isChecked()));
        }
      });
}
 
Example #12
Source File: ChipTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoCustomAccessibilityDelegate() {
  chip.setCloseIconResource(R.drawable.ic_mtrl_chip_close_circle);
  AccessibilityDelegateCompat accessibilityDelegate = ViewCompat.getAccessibilityDelegate(chip);
  assertThat(accessibilityDelegate).isNull();
}
 
Example #13
Source File: PreferenceRecyclerViewAccessibilityDelegate.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
@Override
public AccessibilityDelegateCompat getItemDelegate() {
    return mItemDelegate;
}
 
Example #14
Source File: RecyclerViewAccessibilityDelegate.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the AccessibilityDelegate for an individual item in the RecyclerView.
 * A basic item delegate is provided by default, but you can override this
 * method to provide a custom per-item delegate.
 */
@NonNull
public AccessibilityDelegateCompat getItemDelegate() {
    return mItemDelegate;
}
 
Example #15
Source File: RecyclerViewAccessibilityDelegate.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the AccessibilityDelegate for an individual item in the RecyclerView.
 * A basic item delegate is provided by default, but you can override this
 * method to provide a custom per-item delegate.
 */
@NonNull
public AccessibilityDelegateCompat getItemDelegate() {
    return mItemDelegate;
}