/*
* Copyright (C) 2011 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 android.support.v4.view.accessibility;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat;
import android.support.v4.view.ViewCompat;
import android.text.InputType;
import android.view.View;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Helper for accessing {@link android.view.accessibility.AccessibilityNodeInfo}
* introduced after API level 4 in a backwards compatible fashion.
*/
public class AccessibilityNodeInfoCompat {
public static class AccessibilityActionCompat {
/**
* Action that gives input focus to the node.
*/
public static final AccessibilityActionCompat ACTION_FOCUS =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_FOCUS, null);
/**
* Action that clears input focus of the node.
*/
public static final AccessibilityActionCompat ACTION_CLEAR_FOCUS =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS, null);
/**
* Action that selects the node.
*/
public static final AccessibilityActionCompat ACTION_SELECT =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_SELECT, null);
/**
* Action that deselects the node.
*/
public static final AccessibilityActionCompat ACTION_CLEAR_SELECTION =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION, null);
/**
* Action that clicks on the node info.
*/
public static final AccessibilityActionCompat ACTION_CLICK =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLICK, null);
/**
* Action that long clicks on the node.
*/
public static final AccessibilityActionCompat ACTION_LONG_CLICK =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_LONG_CLICK, null);
/**
* Action that gives accessibility focus to the node.
*/
public static final AccessibilityActionCompat ACTION_ACCESSIBILITY_FOCUS =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS, null);
/**
* Action that clears accessibility focus of the node.
*/
public static final AccessibilityActionCompat ACTION_CLEAR_ACCESSIBILITY_FOCUS =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null);
/**
* Action that requests to go to the next entity in this node's text
* at a given movement granularity. For example, move to the next character,
* word, etc.
*
* Arguments:
* {@link AccessibilityNodeInfoCompat#ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT},
* {@link AccessibilityNodeInfoCompat#ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN}
* Example: Move to the previous character and do not extend selection.
*
*
*
* @see AccessibilityNodeInfoCompat#ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
* @see AccessibilityNodeInfoCompat#ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
*
* @see AccessibilityNodeInfoCompat#setMovementGranularities(int)
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
* @see AccessibilityNodeInfoCompat#getMovementGranularities()
* AccessibilityNodeInfoCompat.getMovementGranularities()
*
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_CHARACTER
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_WORD
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_WORD
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_LINE
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_PARAGRAPH
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_PAGE
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PAGE
*/
public static final AccessibilityActionCompat ACTION_NEXT_AT_MOVEMENT_GRANULARITY =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, null);
/**
* Action that requests to go to the previous entity in this node's text
* at a given movement granularity. For example, move to the next character,
* word, etc.
*
* Arguments:
* {@link AccessibilityNodeInfoCompat#ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT},
* {@link AccessibilityNodeInfoCompat#ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN}
* Example: Move to the next character and do not extend selection.
*
*
*
* @see AccessibilityNodeInfoCompat#ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
* @see AccessibilityNodeInfoCompat#ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
*
* @see AccessibilityNodeInfoCompat#setMovementGranularities(int)
* AccessibilityNodeInfoCompat.setMovementGranularities(int)
* @see AccessibilityNodeInfoCompat#getMovementGranularities()
* AccessibilityNodeInfoCompat.getMovementGranularities()
*
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_CHARACTER
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_WORD
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_WORD
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_LINE
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_PARAGRAPH
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH
* @see AccessibilityNodeInfoCompat#MOVEMENT_GRANULARITY_PAGE
* AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PAGE
*/
public static final AccessibilityActionCompat ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, null);
/**
* Action to move to the next HTML element of a given type. For example, move
* to the BUTTON, INPUT, TABLE, etc.
*
*
*/
public static final AccessibilityActionCompat ACTION_NEXT_HTML_ELEMENT =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT, null);
/**
* Action to move to the previous HTML element of a given type. For example, move
* to the BUTTON, INPUT, TABLE, etc.
*
*
*/
public static final AccessibilityActionCompat ACTION_PREVIOUS_HTML_ELEMENT =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT, null);
/**
* Action to scroll the node content forward.
*/
public static final AccessibilityActionCompat ACTION_SCROLL_FORWARD =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD, null);
/**
* Action to scroll the node content backward.
*/
public static final AccessibilityActionCompat ACTION_SCROLL_BACKWARD =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD, null);
/**
* Action to copy the current selection to the clipboard.
*/
public static final AccessibilityActionCompat ACTION_COPY =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_COPY, null);
/**
* Action to paste the current clipboard content.
*/
public static final AccessibilityActionCompat ACTION_PASTE =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_PASTE, null);
/**
* Action to cut the current selection and place it to the clipboard.
*/
public static final AccessibilityActionCompat ACTION_CUT =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CUT, null);
/**
* Action to set the selection. Performing this action with no arguments
* clears the selection.
*
*
*
* @see AccessibilityNodeInfoCompat#ACTION_ARGUMENT_SELECTION_START_INT
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SELECTION_START_INT
* @see AccessibilityNodeInfoCompat#ACTION_ARGUMENT_SELECTION_END_INT
* AccessibilityNodeInfoCompat.ACTION_ARGUMENT_SELECTION_END_INT
*/
public static final AccessibilityActionCompat ACTION_SET_SELECTION =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_SET_SELECTION, null);
/**
* Action to expand an expandable node.
*/
public static final AccessibilityActionCompat ACTION_EXPAND =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_EXPAND, null);
/**
* Action to collapse an expandable node.
*/
public static final AccessibilityActionCompat ACTION_COLLAPSE =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_COLLAPSE, null);
/**
* Action to dismiss a dismissable node.
*/
public static final AccessibilityActionCompat ACTION_DISMISS =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_DISMISS, null);
/**
* Action that sets the text of the node. Performing the action without argument,
* using null or empty {@link CharSequence} will clear the text. This
* action will also put the cursor at the end of text.
*
*/
public static final AccessibilityActionCompat ACTION_SET_TEXT =
new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_SET_TEXT, null);
private final Object mAction;
/**
* Creates a new instance.
*
* @param actionId The action id.
* @param label The action label.
*/
public AccessibilityActionCompat(int actionId, CharSequence label) {
this(IMPL.newAccessibilityAction(actionId, label));
}
private AccessibilityActionCompat(Object action) {
mAction = action;
}
/**
* Gets the id for this action.
*
* @return The action id.
*/
public int getId() {
return IMPL.getAccessibilityActionId(mAction);
}
/**
* Gets the label for this action. Its purpose is to describe the
* action to user.
*
* @return The label.
*/
public CharSequence getLabel() {
return IMPL.getAccessibilityActionLabel(mAction);
}
}
public static class CollectionInfoCompat {
/** Selection mode where items are not selectable. */
public static final int SELECTION_MODE_NONE = 0;
/** Selection mode where a single item may be selected. */
public static final int SELECTION_MODE_SINGLE = 1;
/** Selection mode where multiple items may be selected. */
public static final int SELECTION_MODE_MULTIPLE = 2;
final Object mInfo;
/**
* Returns a cached instance if such is available otherwise a new one.
*
* @return An instance.
*/
public static CollectionInfoCompat obtain(int rowCount, int columnCount,
boolean hierarchical, int selectionMode) {
return new CollectionInfoCompat(IMPL.obtainCollectionInfo(rowCount, columnCount,
hierarchical, selectionMode));
}
private CollectionInfoCompat(Object info) {
mInfo = info;
}
public int getColumnCount() {
return IMPL.getCollectionInfoColumnCount(mInfo);
}
public int getRowCount() {
return IMPL.getCollectionInfoRowCount(mInfo);
}
public boolean isHierarchical() {
return IMPL.isCollectionInfoHierarchical(mInfo);
}
}
public static class CollectionItemInfoCompat {
private final Object mInfo;
/**
* Returns a cached instance if such is available otherwise a new one.
*
* @return An instance.
*/
public static CollectionItemInfoCompat obtain(int rowIndex, int rowSpan,
int columnIndex, int columnSpan, boolean heading, boolean selected) {
return new CollectionItemInfoCompat(IMPL.obtainCollectionItemInfo(rowIndex, rowSpan,
columnIndex, columnSpan, heading, selected));
}
private CollectionItemInfoCompat(Object info) {
mInfo = info;
}
public int getColumnIndex() {
return IMPL.getCollectionItemColumnIndex(mInfo);
}
public int getColumnSpan() {
return IMPL.getCollectionItemColumnSpan(mInfo);
}
public int getRowIndex() {
return IMPL.getCollectionItemRowIndex(mInfo);
}
public int getRowSpan() {
return IMPL.getCollectionItemRowSpan(mInfo);
}
public boolean isHeading() {
return IMPL.isCollectionItemHeading(mInfo);
}
public boolean isSelected() {
return IMPL.isCollectionItemSelected(mInfo);
}
}
public static class RangeInfoCompat {
/** Range type: integer. */
public static final int RANGE_TYPE_INT = 0;
/** Range type: float. */
public static final int RANGE_TYPE_FLOAT = 1;
/** Range type: percent with values from zero to one.*/
public static final int RANGE_TYPE_PERCENT = 2;
private final Object mInfo;
private RangeInfoCompat(Object info) {
mInfo = info;
}
public float getCurrent() {
return AccessibilityNodeInfoCompatKitKat.RangeInfo.getCurrent(mInfo);
}
public float getMax() {
return AccessibilityNodeInfoCompatKitKat.RangeInfo.getMax(mInfo);
}
public float getMin() {
return AccessibilityNodeInfoCompatKitKat.RangeInfo.getMin(mInfo);
}
public int getType() {
return AccessibilityNodeInfoCompatKitKat.RangeInfo.getType(mInfo);
}
}
static interface AccessibilityNodeInfoImpl {
public Object newAccessibilityAction(int actionId, CharSequence label);
public Object obtain();
public Object obtain(View source);
public Object obtain(Object info);
public Object obtain(View root, int virtualDescendantId);
public void setSource(Object info, View source);
public void setSource(Object info, View root, int virtualDescendantId);
public Object findFocus(Object info, int focus);
public Object focusSearch(Object info, int direction);
public int getWindowId(Object info);
public int getChildCount(Object info);
public Object getChild(Object info, int index);
public void addChild(Object info, View child);
public void addChild(Object info, View child, int virtualDescendantId);
public boolean removeChild(Object info, View child);
public boolean removeChild(Object info, View root, int virtualDescendantId);
public int getActions(Object info);
public void addAction(Object info, int action);
public void addAction(Object info, Object action);
public boolean removeAction(Object info, Object action);
public int getAccessibilityActionId(Object action);
public CharSequence getAccessibilityActionLabel(Object action);
public boolean performAction(Object info, int action);
public boolean performAction(Object info, int action, Bundle arguments);
public void setMovementGranularities(Object info, int granularities);
public int getMovementGranularities(Object info);
public List