public class

PreferenceRecyclerViewAccessibilityDelegate

extends RecyclerViewAccessibilityDelegate

 java.lang.Object

androidx.core.view.AccessibilityDelegateCompat

androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate

↳androidx.preference.PreferenceRecyclerViewAccessibilityDelegate

Gradle dependencies

compile group: 'androidx.preference', name: 'preference', version: '1.2.1'

  • groupId: androidx.preference
  • artifactId: preference
  • version: 1.2.1

Artifact androidx.preference:preference:1.2.1 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.preference:preference com.android.support:preference-v7

Androidx class mapping:

androidx.preference.PreferenceRecyclerViewAccessibilityDelegate android.support.v7.preference.PreferenceRecyclerViewAccessibilityDelegate

Overview

The accessibility delegate used by the RecyclerView that displays views for Preferences. Used by Leanback.

Summary

Constructors
publicPreferenceRecyclerViewAccessibilityDelegate(RecyclerView recyclerView)

Methods
public AccessibilityDelegateCompatgetItemDelegate()

Gets the AccessibilityDelegate for an individual item in the RecyclerView.

from RecyclerViewAccessibilityDelegateonInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, performAccessibilityAction
from AccessibilityDelegateCompatdispatchPopulateAccessibilityEvent, getAccessibilityNodeProvider, onPopulateAccessibilityEvent, onRequestSendAccessibilityEvent, sendAccessibilityEvent, sendAccessibilityEventUnchecked
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public PreferenceRecyclerViewAccessibilityDelegate(RecyclerView recyclerView)

Methods

public AccessibilityDelegateCompat getItemDelegate()

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. For now, returning an AccessibilityDelegateCompat as opposed to an ItemDelegate will prevent use of the ViewCompat accessibility API on item views.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.preference;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate;

/**
 * The accessibility delegate used by the {@link RecyclerView} that displays views for
 * {@link Preference}s.
 *
 * Used by Leanback.
 *
 * @hide
 * @deprecated This class is used to set AccessibilityNodeInfo for {@link Preference}. Preference
 * class deprecated the API onInitializeAccessibilityNodeInfo.
 */
@Deprecated
@RestrictTo(LIBRARY_GROUP_PREFIX)
public class PreferenceRecyclerViewAccessibilityDelegate
        extends RecyclerViewAccessibilityDelegate {
    @SuppressWarnings("WeakerAccess") /* synthetic access */
    final RecyclerView mRecyclerView;
    @SuppressWarnings("WeakerAccess") /* synthetic access */
    final AccessibilityDelegateCompat mDefaultItemDelegate = super.getItemDelegate();

    public PreferenceRecyclerViewAccessibilityDelegate(@NonNull RecyclerView recyclerView) {
        super(recyclerView);
        mRecyclerView = recyclerView;
    }

    @NonNull
    @Override
    public AccessibilityDelegateCompat getItemDelegate() {
        return mItemDelegate;
    }
    @SuppressWarnings("WeakerAccess") /* synthetic access */
    final AccessibilityDelegateCompat mItemDelegate = new AccessibilityDelegateCompat() {
        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            mDefaultItemDelegate.onInitializeAccessibilityNodeInfo(host, info);
            int position = mRecyclerView.getChildAdapterPosition(host);

            RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
            if (!(adapter instanceof PreferenceGroupAdapter)) {
                return;
            }

            PreferenceGroupAdapter preferenceGroupAdapter = (PreferenceGroupAdapter) adapter;
            Preference preference = preferenceGroupAdapter.getItem(position);
            if (preference == null) {
                return;
            }

            preference.onInitializeAccessibilityNodeInfo(info);
        }

        @Override
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
            // Must forward actions since the default delegate will handle actions.
            return mDefaultItemDelegate.performAccessibilityAction(host, action, args);
        }
    };
}