public class

AccessibilityWindowInfoCompat

extends java.lang.Object

 java.lang.Object

↳androidx.core.view.accessibility.AccessibilityWindowInfoCompat

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.9.0-alpha04'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.9.0-alpha04

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

Androidx artifact mapping:

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

Androidx class mapping:

androidx.core.view.accessibility.AccessibilityWindowInfoCompat android.support.v4.view.accessibility.AccessibilityWindowInfoCompat

Overview

Helper for accessing .

Summary

Fields
public static final intTYPE_ACCESSIBILITY_OVERLAY

Window type: Windows that are overlaid only by an for interception of user interactions without changing the windows an accessibility service can introspect.

public static final intTYPE_APPLICATION

Window type: This is an application window.

public static final intTYPE_INPUT_METHOD

Window type: This is an input method window.

public static final intTYPE_SPLIT_SCREEN_DIVIDER

Window type: A system window used to divide the screen in split-screen mode.

public static final intTYPE_SYSTEM

Window type: This is an system window.

Methods
public booleanequals(java.lang.Object obj)

public AccessibilityNodeInfoCompatgetAnchor()

Gets the node that anchors this window to another.

public voidgetBoundsInScreen(Rect outBounds)

Gets the bounds of this window in the screen.

public AccessibilityWindowInfoCompatgetChild(int index)

Gets the child window at a given index.

public intgetChildCount()

Gets the number of child windows.

public intgetId()

Gets the unique window id.

public intgetLayer()

Gets the layer which determines the Z-order of the window.

public AccessibilityWindowInfoCompatgetParent()

Gets the parent window if such.

public AccessibilityNodeInfoCompatgetRoot()

Gets the root node in the window's hierarchy.

public java.lang.CharSequencegetTitle()

Gets the title of the window.

public intgetType()

Gets the type of the window.

public inthashCode()

public booleanisAccessibilityFocused()

Gets if this window has accessibility focus.

public booleanisActive()

Gets if this window is active.

public booleanisFocused()

Gets if this window has input focus.

public static AccessibilityWindowInfoCompatobtain()

Returns a cached instance if such is available or a new one is created.

public static AccessibilityWindowInfoCompatobtain(AccessibilityWindowInfoCompat info)

Returns a cached instance if such is available or a new one is created.

public voidrecycle()

Return an instance back to be reused.

public java.lang.StringtoString()

from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Fields

public static final int TYPE_APPLICATION

Window type: This is an application window. Such a window shows UI for interacting with an application.

public static final int TYPE_INPUT_METHOD

Window type: This is an input method window. Such a window shows UI for inputting text such as keyboard, suggestions, etc.

public static final int TYPE_SYSTEM

Window type: This is an system window. Such a window shows UI for interacting with the system.

public static final int TYPE_ACCESSIBILITY_OVERLAY

Window type: Windows that are overlaid only by an for interception of user interactions without changing the windows an accessibility service can introspect. In particular, an accessibility service can introspect only windows that a sighted user can interact with which they can touch these windows or can type into these windows. For example, if there is a full screen accessibility overlay that is touchable, the windows below it will be introspectable by an accessibility service regardless they are covered by a touchable window.

public static final int TYPE_SPLIT_SCREEN_DIVIDER

Window type: A system window used to divide the screen in split-screen mode. This type of window is present only in split-screen mode.

Methods

public int getType()

Gets the type of the window.

Returns:

The type.

See also: AccessibilityWindowInfoCompat.TYPE_APPLICATION, AccessibilityWindowInfoCompat.TYPE_INPUT_METHOD, AccessibilityWindowInfoCompat.TYPE_SYSTEM, AccessibilityWindowInfoCompat.TYPE_ACCESSIBILITY_OVERLAY

public int getLayer()

Gets the layer which determines the Z-order of the window. Windows with greater layer appear on top of windows with lesser layer.

Returns:

The window layer.

Gets the root node in the window's hierarchy.

Returns:

The root node.

Gets the parent window if such.

Returns:

The parent window.

public int getId()

Gets the unique window id.

Returns:

windowId The window id.

public void getBoundsInScreen(Rect outBounds)

Gets the bounds of this window in the screen.

Parameters:

outBounds: The out window bounds.

public boolean isActive()

Gets if this window is active. An active window is the one the user is currently touching or the window has input focus and the user is not touching any window.

Returns:

Whether this is the active window.

public boolean isFocused()

Gets if this window has input focus.

Returns:

Whether has input focus.

public boolean isAccessibilityFocused()

Gets if this window has accessibility focus.

Returns:

Whether has accessibility focus.

public int getChildCount()

Gets the number of child windows.

Returns:

The child count.

public AccessibilityWindowInfoCompat getChild(int index)

Gets the child window at a given index.

Parameters:

index: The index.

Returns:

The child.

public java.lang.CharSequence getTitle()

Gets the title of the window.

Returns:

The title of the window, or the application label for the window if no title was explicitly set, or null if neither is available.

public AccessibilityNodeInfoCompat getAnchor()

Gets the node that anchors this window to another.

Returns:

The anchor node, or null if none exists.

public static AccessibilityWindowInfoCompat obtain()

Returns a cached instance if such is available or a new one is created.

Returns:

An instance.

Returns a cached instance if such is available or a new one is created. The returned instance is initialized from the given info.

Parameters:

info: The other info.

Returns:

An instance.

public void recycle()

Return an instance back to be reused.

Note: You must not touch the object after calling this function.

public int hashCode()

public boolean equals(java.lang.Object obj)

public java.lang.String toString()

Source

/*
 * Copyright (C) 2015 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 android.os.Build.VERSION.SDK_INT;

import android.graphics.Rect;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;

import androidx.annotation.DoNotInline;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

/**
 * Helper for accessing {@link android.view.accessibility.AccessibilityWindowInfo}.
 */
public class AccessibilityWindowInfoCompat {
    private final Object mInfo;

    private static final int UNDEFINED = -1;

    /**
     * Window type: This is an application window. Such a window shows UI for
     * interacting with an application.
     */
    public static final int TYPE_APPLICATION = 1;

    /**
     * Window type: This is an input method window. Such a window shows UI for
     * inputting text such as keyboard, suggestions, etc.
     */
    public static final int TYPE_INPUT_METHOD = 2;

    /**
     * Window type: This is an system window. Such a window shows UI for
     * interacting with the system.
     */
    public static final int TYPE_SYSTEM = 3;

    /**
     * Window type: Windows that are overlaid <em>only</em> by an {@link
     * android.accessibilityservice.AccessibilityService} for interception of
     * user interactions without changing the windows an accessibility service
     * can introspect. In particular, an accessibility service can introspect
     * only windows that a sighted user can interact with which they can touch
     * these windows or can type into these windows. For example, if there
     * is a full screen accessibility overlay that is touchable, the windows
     * below it will be introspectable by an accessibility service regardless
     * they are covered by a touchable window.
     */
    public static final int TYPE_ACCESSIBILITY_OVERLAY = 4;

    /**
     * Window type: A system window used to divide the screen in split-screen mode.
     * This type of window is present only in split-screen mode.
     */
    public static final int TYPE_SPLIT_SCREEN_DIVIDER = 5;

    /**
     * Creates a wrapper for info implementation.
     *
     * @param object The info to wrap.
     * @return A wrapper for if the object is not null, null otherwise.
     */
    static AccessibilityWindowInfoCompat wrapNonNullInstance(Object object) {
        if (object != null) {
            return new AccessibilityWindowInfoCompat(object);
        }
        return null;
    }

    private AccessibilityWindowInfoCompat(Object info) {
        mInfo = info;
    }

    /**
     * Gets the type of the window.
     *
     * @return The type.
     * @see #TYPE_APPLICATION
     * @see #TYPE_INPUT_METHOD
     * @see #TYPE_SYSTEM
     * @see #TYPE_ACCESSIBILITY_OVERLAY
     */
    public int getType() {
        if (SDK_INT >= 21) {
            return Api21Impl.getType((AccessibilityWindowInfo) mInfo);
        } else {
            return UNDEFINED;
        }
    }

    /**
     * Gets the layer which determines the Z-order of the window. Windows
     * with greater layer appear on top of windows with lesser layer.
     *
     * @return The window layer.
     */
    public int getLayer() {
        if (SDK_INT >= 21) {
            return Api21Impl.getLayer((AccessibilityWindowInfo) mInfo);
        } else {
            return UNDEFINED;
        }
    }

    /**
     * Gets the root node in the window's hierarchy.
     *
     * @return The root node.
     */
    @Nullable
    public AccessibilityNodeInfoCompat getRoot() {
        if (SDK_INT >= 21) {
            return AccessibilityNodeInfoCompat.wrapNonNullInstance(
                    Api21Impl.getRoot((AccessibilityWindowInfo) mInfo));
        } else {
            return null;
        }
    }

    /**
     * Gets the parent window if such.
     *
     * @return The parent window.
     */
    @Nullable
    public AccessibilityWindowInfoCompat getParent() {
        if (SDK_INT >= 21) {
            return wrapNonNullInstance(Api21Impl.getParent((AccessibilityWindowInfo) mInfo));
        } else {
            return null;
        }
    }

    /**
     * Gets the unique window id.
     *
     * @return windowId The window id.
     */
    public int getId() {
        if (SDK_INT >= 21) {
            return Api21Impl.getId((AccessibilityWindowInfo) mInfo);
        } else {
            return UNDEFINED;
        }
    }

    /**
     * Gets the bounds of this window in the screen.
     *
     * @param outBounds The out window bounds.
     */
    public void getBoundsInScreen(@NonNull Rect outBounds) {
        if (SDK_INT >= 21) {
            Api21Impl.getBoundsInScreen((AccessibilityWindowInfo) mInfo, outBounds);
        }
    }

    /**
     * Gets if this window is active. An active window is the one
     * the user is currently touching or the window has input focus
     * and the user is not touching any window.
     *
     * @return Whether this is the active window.
     */
    public boolean isActive() {
        if (SDK_INT >= 21) {
            return Api21Impl.isActive((AccessibilityWindowInfo) mInfo);
        } else {
            return true;
        }
    }

    /**
     * Gets if this window has input focus.
     *
     * @return Whether has input focus.
     */
    public boolean isFocused() {
        if (SDK_INT >= 21) {
            return Api21Impl.isFocused((AccessibilityWindowInfo) mInfo);
        } else {
            return true;
        }
    }

    /**
     * Gets if this window has accessibility focus.
     *
     * @return Whether has accessibility focus.
     */
    public boolean isAccessibilityFocused() {
        if (SDK_INT >= 21) {
            return Api21Impl.isAccessibilityFocused((AccessibilityWindowInfo) mInfo);
        } else {
            return true;
        }
    }

    /**
     * Gets the number of child windows.
     *
     * @return The child count.
     */
    public int getChildCount() {
        if (SDK_INT >= 21) {
            return Api21Impl.getChildCount((AccessibilityWindowInfo) mInfo);
        } else {
            return 0;
        }
    }

    /**
     * Gets the child window at a given index.
     *
     * @param index The index.
     * @return The child.
     */
    @Nullable
    public AccessibilityWindowInfoCompat getChild(int index) {
        if (SDK_INT >= 21) {
            return wrapNonNullInstance(Api21Impl.getChild((AccessibilityWindowInfo) mInfo, index));
        } else {
            return null;
        }
    }

    /**
     * Gets the title of the window.
     *
     * @return The title of the window, or the application label for the window if no title was
     * explicitly set, or {@code null} if neither is available.
     */
    @Nullable
    public CharSequence getTitle() {
        if (SDK_INT >= 24) {
            return Api24Impl.getTitle((AccessibilityWindowInfo) mInfo);
        } else {
            return null;
        }
    }

    /**
     * Gets the node that anchors this window to another.
     *
     * @return The anchor node, or {@code null} if none exists.
     */
    @Nullable
    public AccessibilityNodeInfoCompat getAnchor() {
        if (SDK_INT >= 24) {
            return AccessibilityNodeInfoCompat.wrapNonNullInstance(
                    Api24Impl.getAnchor((AccessibilityWindowInfo) mInfo));
        } else {
            return null;
        }
    }

    /**
     * Returns a cached instance if such is available or a new one is
     * created.
     *
     * @return An instance.
     */
    @Nullable
    public static AccessibilityWindowInfoCompat obtain() {
        if (SDK_INT >= 21) {
            return wrapNonNullInstance(Api21Impl.obtain());
        } else {
            return null;
        }
    }

    /**
     * Returns a cached instance if such is available or a new one is
     * created. The returned instance is initialized from the given
     * <code>info</code>.
     *
     * @param info The other info.
     * @return An instance.
     */
    @Nullable
    public static AccessibilityWindowInfoCompat obtain(
            @Nullable AccessibilityWindowInfoCompat info) {
        if (SDK_INT >= 21) {
            return info == null
                    ? null
                    : wrapNonNullInstance(
                            Api21Impl.obtain((AccessibilityWindowInfo) info.mInfo));
        } else {
            return null;
        }
    }

    /**
     * Return an instance back to be reused.
     * <p>
     * <strong>Note:</strong> You must not touch the object after calling this function.
     * </p>
     *
     * @throws IllegalStateException If the info is already recycled.
     */
    public void recycle() {
        if (SDK_INT >= 21) {
            Api21Impl.recycle((AccessibilityWindowInfo) mInfo);
        }
    }

    @Override
    public int hashCode() {
        return (mInfo == null) ? 0 : mInfo.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof AccessibilityWindowInfoCompat)) {
            return false;
        }
        AccessibilityWindowInfoCompat other = (AccessibilityWindowInfoCompat) obj;
        if (mInfo == null) {
            return other.mInfo == null;
        }
        return mInfo.equals(other.mInfo);
    }

    @NonNull
    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        Rect bounds = new Rect();
        getBoundsInScreen(bounds);
        builder.append("AccessibilityWindowInfo[");
        builder.append("id=").append(getId());
        builder.append(", type=").append(typeToString(getType()));
        builder.append(", layer=").append(getLayer());
        builder.append(", bounds=").append(bounds);
        builder.append(", focused=").append(isFocused());
        builder.append(", active=").append(isActive());
        builder.append(", hasParent=").append(getParent() != null);
        builder.append(", hasChildren=").append(getChildCount() > 0);
        builder.append(']');
        return builder.toString();
    }

    private static String typeToString(int type) {
        switch (type) {
            case TYPE_APPLICATION: {
                return "TYPE_APPLICATION";
            }
            case TYPE_INPUT_METHOD: {
                return "TYPE_INPUT_METHOD";
            }
            case TYPE_SYSTEM: {
                return "TYPE_SYSTEM";
            }
            case TYPE_ACCESSIBILITY_OVERLAY: {
                return "TYPE_ACCESSIBILITY_OVERLAY";
            }
            default:
                return "<UNKNOWN>";
        }
    }

    @RequiresApi(21)
    private static class Api21Impl {
        private Api21Impl() {
            // This class is not instantiable.
        }

        @DoNotInline
        static void getBoundsInScreen(AccessibilityWindowInfo info, Rect outBounds) {
            info.getBoundsInScreen(outBounds);
        }

        @DoNotInline
        static AccessibilityWindowInfo getChild(AccessibilityWindowInfo info, int index) {
            return info.getChild(index);
        }

        @DoNotInline
        static int getChildCount(AccessibilityWindowInfo info) {
            return info.getChildCount();
        }

        @DoNotInline
        static int getId(AccessibilityWindowInfo info) {
            return info.getId();
        }

        @DoNotInline
        static int getLayer(AccessibilityWindowInfo info) {
            return info.getLayer();
        }

        @DoNotInline
        static AccessibilityWindowInfo getParent(AccessibilityWindowInfo info) {
            return info.getParent();
        }

        @DoNotInline
        static AccessibilityNodeInfo getRoot(AccessibilityWindowInfo info) {
            return info.getRoot();
        }

        @DoNotInline
        static int getType(AccessibilityWindowInfo info) {
            return info.getType();
        }

        @DoNotInline
        static boolean isAccessibilityFocused(AccessibilityWindowInfo info) {
            return info.isAccessibilityFocused();
        }

        @DoNotInline
        static boolean isActive(AccessibilityWindowInfo info) {
            return info.isActive();
        }

        @DoNotInline
        static boolean isFocused(AccessibilityWindowInfo info) {
            return info.isFocused();
        }

        @DoNotInline
        static AccessibilityWindowInfo obtain() {
            return AccessibilityWindowInfo.obtain();
        }

        @DoNotInline
        static AccessibilityWindowInfo obtain(AccessibilityWindowInfo info) {
            return AccessibilityWindowInfo.obtain(info);
        }

        @DoNotInline
        static void recycle(AccessibilityWindowInfo info) {
            info.recycle();
        }
    }

    @RequiresApi(24)
    private static class Api24Impl {
        private Api24Impl() {
            // This class is not instantiable.
        }

        @DoNotInline
        static AccessibilityNodeInfo getAnchor(AccessibilityWindowInfo info) {
            return info.getAnchor();
        }

        @DoNotInline
        static CharSequence getTitle(AccessibilityWindowInfo info) {
            return info.getTitle();
        }
    }
}