public final class

AccessibilityClickableSpanCompat

extends ClickableSpan

 java.lang.Object

↳ClickableSpan

↳androidx.core.view.accessibility.AccessibilityClickableSpanCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Overview

cannot be parceled, but accessibility services need to be able to cause their callback handlers to be called. This class serves as a placeholder for the real spans. Calling onClick on these from an accessibility service will result in onClick being called on the represented span in the app process.

Summary

Fields
public static final java.lang.StringSPAN_ID

Constructors
publicAccessibilityClickableSpanCompat(int originalClickableSpanId, AccessibilityNodeInfoCompat nodeInfoCompat, int clickableSpanActionId)

Methods
public voidonClick(View unused)

Perform the click from an accessibility service.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final java.lang.String SPAN_ID

Constructors

public AccessibilityClickableSpanCompat(int originalClickableSpanId, AccessibilityNodeInfoCompat nodeInfoCompat, int clickableSpanActionId)

Parameters:

originalClickableSpanId: The id of the span this one replaces
nodeInfoCompat: The nodeInfoCompat to be associated with this span.

Methods

public void onClick(View unused)

Perform the click from an accessibility service.

Parameters:

unused: This argument is required by the superclass but is unused. The real view will be determined by the AccessibilityNodeInfo.

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.core.view.accessibility;

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

import android.os.Bundle;
import android.text.style.ClickableSpan;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

/**
 * {@link ClickableSpan} cannot be parceled, but accessibility services need to be able to cause
 * their callback handlers to be called. This class serves as a placeholder for the
 * real spans. Calling onClick on these from an accessibility service will result in onClick being
 * called on the represented span in the app process.
 */
public final class AccessibilityClickableSpanCompat extends ClickableSpan {

    // The id of the span this one replaces
    private final int mOriginalClickableSpanId;

    private final AccessibilityNodeInfoCompat mNodeInfoCompat;

    private final int mClickableSpanActionId;

    /**
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    public static final String SPAN_ID = "ACCESSIBILITY_CLICKABLE_SPAN_ID";

    /**
     * @param originalClickableSpanId The id of the span this one replaces
     * @param nodeInfoCompat The nodeInfoCompat to be associated with this span.
     */
    @RestrictTo(LIBRARY_GROUP_PREFIX)
    public AccessibilityClickableSpanCompat(int originalClickableSpanId,
            @NonNull AccessibilityNodeInfoCompat nodeInfoCompat, int clickableSpanActionId) {
        mOriginalClickableSpanId = originalClickableSpanId;
        mNodeInfoCompat = nodeInfoCompat;
        mClickableSpanActionId = clickableSpanActionId;
    }

    /**
     * Perform the click from an accessibility service.
     *
     * @param unused This argument is required by the superclass but is unused. The real view will
     * be determined by the AccessibilityNodeInfo.
     */
    @Override
    public void onClick(@NonNull View unused) {
        Bundle arguments = new Bundle();
        arguments.putInt(SPAN_ID, mOriginalClickableSpanId);
        mNodeInfoCompat.performAction(mClickableSpanActionId, arguments);
    }
}