Merge "Add accessibility window title and anchor." into nyc-dev

This commit is contained in:
Phil Weaver
2016-04-04 16:36:00 +00:00
committed by Android (Google) Code Review
10 changed files with 119 additions and 3 deletions

View File

@@ -44260,6 +44260,7 @@ package android.view.accessibility {
public final class AccessibilityWindowInfo implements android.os.Parcelable {
method public int describeContents();
method public android.view.accessibility.AccessibilityNodeInfo getAnchor();
method public void getBoundsInScreen(android.graphics.Rect);
method public android.view.accessibility.AccessibilityWindowInfo getChild(int);
method public int getChildCount();
@@ -44267,6 +44268,7 @@ package android.view.accessibility {
method public int getLayer();
method public android.view.accessibility.AccessibilityWindowInfo getParent();
method public android.view.accessibility.AccessibilityNodeInfo getRoot();
method public java.lang.CharSequence getTitle();
method public int getType();
method public boolean isAccessibilityFocused();
method public boolean isActive();

View File

@@ -47003,6 +47003,7 @@ package android.view.accessibility {
public final class AccessibilityWindowInfo implements android.os.Parcelable {
method public int describeContents();
method public android.view.accessibility.AccessibilityNodeInfo getAnchor();
method public void getBoundsInScreen(android.graphics.Rect);
method public android.view.accessibility.AccessibilityWindowInfo getChild(int);
method public int getChildCount();
@@ -47010,6 +47011,7 @@ package android.view.accessibility {
method public int getLayer();
method public android.view.accessibility.AccessibilityWindowInfo getParent();
method public android.view.accessibility.AccessibilityNodeInfo getRoot();
method public java.lang.CharSequence getTitle();
method public int getType();
method public boolean isAccessibilityFocused();
method public boolean isActive();

View File

@@ -44334,6 +44334,7 @@ package android.view.accessibility {
public final class AccessibilityWindowInfo implements android.os.Parcelable {
method public int describeContents();
method public android.view.accessibility.AccessibilityNodeInfo getAnchor();
method public void getBoundsInScreen(android.graphics.Rect);
method public android.view.accessibility.AccessibilityWindowInfo getChild(int);
method public int getChildCount();
@@ -44341,6 +44342,7 @@ package android.view.accessibility {
method public int getLayer();
method public android.view.accessibility.AccessibilityWindowInfo getParent();
method public android.view.accessibility.AccessibilityNodeInfo getRoot();
method public java.lang.CharSequence getTitle();
method public int getType();
method public boolean isAccessibilityFocused();
method public boolean isActive();

View File

@@ -44,6 +44,8 @@ public class WindowInfo implements Parcelable {
public boolean focused;
public final Rect boundsInScreen = new Rect();
public List<IBinder> childTokens;
public CharSequence title;
public int accessibilityIdOfAnchor = View.NO_ID;
private WindowInfo() {
/* do nothing - hide constructor */
@@ -65,6 +67,8 @@ public class WindowInfo implements Parcelable {
window.parentToken = other.parentToken;
window.focused = other.focused;
window.boundsInScreen.set(other.boundsInScreen);
window.title = other.title;
window.accessibilityIdOfAnchor = other.accessibilityIdOfAnchor;
if (other.childTokens != null && !other.childTokens.isEmpty()) {
if (window.childTokens == null) {
@@ -95,6 +99,8 @@ public class WindowInfo implements Parcelable {
parcel.writeStrongBinder(parentToken);
parcel.writeInt(focused ? 1 : 0);
boundsInScreen.writeToParcel(parcel, flags);
parcel.writeCharSequence(title);
parcel.writeInt(accessibilityIdOfAnchor);
if (childTokens != null && !childTokens.isEmpty()) {
parcel.writeInt(1);
@@ -108,13 +114,15 @@ public class WindowInfo implements Parcelable {
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WindowInfo[");
builder.append("type=").append(type);
builder.append("title=").append(title);
builder.append(", type=").append(type);
builder.append(", layer=").append(layer);
builder.append(", token=").append(token);
builder.append(", bounds=").append(boundsInScreen);
builder.append(", parent=").append(parentToken);
builder.append(", focused=").append(focused);
builder.append(", children=").append(childTokens);
builder.append(", accessibility anchor=").append(accessibilityIdOfAnchor);
builder.append(']');
return builder.toString();
}
@@ -126,6 +134,8 @@ public class WindowInfo implements Parcelable {
parentToken = parcel.readStrongBinder();
focused = (parcel.readInt() == 1);
boundsInScreen.readFromParcel(parcel);
title = parcel.readCharSequence();
accessibilityIdOfAnchor = parcel.readInt();
final boolean hasChildren = (parcel.readInt() == 1);
if (hasChildren) {

View File

@@ -1693,6 +1693,14 @@ public interface WindowManager extends ViewManager {
*/
public long userActivityTimeout = -1;
/**
* For windows with an anchor (e.g. PopupWindow), keeps track of the View that anchors the
* window.
*
* @hide
*/
public int accessibilityIdOfAnchor = -1;
public LayoutParams() {
super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
type = TYPE_APPLICATION;
@@ -1799,6 +1807,7 @@ public interface WindowManager extends ViewManager {
out.writeInt(surfaceInsets.bottom);
out.writeInt(hasManualSurfaceInsets ? 1 : 0);
out.writeInt(needsMenuKey);
out.writeInt(accessibilityIdOfAnchor);
}
public static final Parcelable.Creator<LayoutParams> CREATOR
@@ -1849,6 +1858,7 @@ public interface WindowManager extends ViewManager {
surfaceInsets.bottom = in.readInt();
hasManualSurfaceInsets = in.readInt() != 0;
needsMenuKey = in.readInt();
accessibilityIdOfAnchor = in.readInt();
}
@SuppressWarnings({"PointlessBitwiseExpression"})
@@ -1888,6 +1898,8 @@ public interface WindowManager extends ViewManager {
/** {@hide} */
public static final int PREFERRED_DISPLAY_MODE_ID = 1 << 23;
/** {@hide} */
public static final int ACCESSIBILITY_ANCHOR_CHANGED = 1 << 24;
/** {@hide} */
public static final int EVERYTHING_CHANGED = 0xffffffff;
// internal buffer to backup/restore parameters under compatibility mode.
@@ -2048,6 +2060,11 @@ public interface WindowManager extends ViewManager {
changes |= NEEDS_MENU_KEY_CHANGED;
}
if (accessibilityIdOfAnchor != o.accessibilityIdOfAnchor) {
accessibilityIdOfAnchor = o.accessibilityIdOfAnchor;
changes |= ACCESSIBILITY_ANCHOR_CHANGED;
}
return changes;
}

View File

@@ -89,6 +89,8 @@ public final class AccessibilityWindowInfo implements Parcelable {
private int mParentId = UNDEFINED;
private final Rect mBoundsInScreen = new Rect();
private LongArray mChildIds;
private CharSequence mTitle;
private int mAnchorId = UNDEFINED;
private int mConnectionId = UNDEFINED;
@@ -96,6 +98,26 @@ public final class AccessibilityWindowInfo implements Parcelable {
/* do nothing - hide constructor */
}
/**
* Gets the title of the window.
*
* @return The title.
*/
public CharSequence getTitle() {
return mTitle;
}
/**
* Sets the title of the window.
*
* @param title The title.
*
* @hide
*/
public void setTitle(CharSequence title) {
mTitle = title;
}
/**
* Gets the type of the window.
*
@@ -159,9 +181,35 @@ public final class AccessibilityWindowInfo implements Parcelable {
}
/**
* Gets the parent window if such.
* Sets the anchor node's ID.
*
* @return The parent window.
* @param anchorId The anchor's accessibility id in its window.
*
* @hide
*/
public void setAnchorId(int anchorId) {
mAnchorId = anchorId;
}
/**
* Gets the node that anchors this window to another.
*
* @return The anchor node, or {@code null} if none exists.
*/
public AccessibilityNodeInfo getAnchor() {
if ((mConnectionId == UNDEFINED) || (mAnchorId == UNDEFINED) || (mParentId == UNDEFINED)) {
return null;
}
AccessibilityInteractionClient client = AccessibilityInteractionClient.getInstance();
return client.findAccessibilityNodeInfoByAccessibilityId(mConnectionId,
mParentId, mAnchorId, true, 0);
}
/**
* Gets the parent window.
*
* @return The parent window, or {@code null} if none exists.
*/
public AccessibilityWindowInfo getParent() {
if (mConnectionId == UNDEFINED || mParentId == UNDEFINED) {
@@ -370,6 +418,8 @@ public final class AccessibilityWindowInfo implements Parcelable {
infoClone.mId = info.mId;
infoClone.mParentId = info.mParentId;
infoClone.mBoundsInScreen.set(info.mBoundsInScreen);
infoClone.mTitle = info.mTitle;
infoClone.mAnchorId = info.mAnchorId;
if (info.mChildIds != null && info.mChildIds.size() > 0) {
if (infoClone.mChildIds == null) {
@@ -410,6 +460,8 @@ public final class AccessibilityWindowInfo implements Parcelable {
parcel.writeInt(mId);
parcel.writeInt(mParentId);
mBoundsInScreen.writeToParcel(parcel, flags);
parcel.writeCharSequence(mTitle);
parcel.writeInt(mAnchorId);
final LongArray childIds = mChildIds;
if (childIds == null) {
@@ -432,6 +484,8 @@ public final class AccessibilityWindowInfo implements Parcelable {
mId = parcel.readInt();
mParentId = parcel.readInt();
mBoundsInScreen.readFromParcel(parcel);
mTitle = parcel.readCharSequence();
mAnchorId = parcel.readInt();
final int childCount = parcel.readInt();
if (childCount > 0) {
@@ -471,6 +525,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("AccessibilityWindowInfo[");
builder.append("title=").append(mTitle);
builder.append("id=").append(mId);
builder.append(", type=").append(typeToString(mType));
builder.append(", layer=").append(mLayer);
@@ -494,6 +549,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
builder.append(']');
} else {
builder.append(", hasParent=").append(mParentId != UNDEFINED);
builder.append(", isAnchored=").append(mAnchorId != UNDEFINED);
builder.append(", hasChildren=").append(mChildIds != null
&& mChildIds.size() > 0);
}
@@ -515,6 +571,8 @@ public final class AccessibilityWindowInfo implements Parcelable {
mChildIds.clear();
}
mConnectionId = UNDEFINED;
mAnchorId = UNDEFINED;
mTitle = null;
}
/**

View File

@@ -1214,6 +1214,7 @@ public class PopupWindow {
final boolean aboveAnchor = findDropDownPosition(anchor, p, xoff, yoff,
p.width, p.height, gravity);
updateAboveAnchor(aboveAnchor);
p.accessibilityIdOfAnchor = (anchor != null) ? anchor.getAccessibilityViewId() : -1;
invokePopup(p);
}
@@ -1984,6 +1985,13 @@ public class PopupWindow {
update = true;
}
int newAccessibilityIdOfAnchor =
(mAnchor != null) ? mAnchor.get().getAccessibilityViewId() : -1;
if (newAccessibilityIdOfAnchor != p.accessibilityIdOfAnchor) {
p.accessibilityIdOfAnchor = newAccessibilityIdOfAnchor;
update = true;
}
if (update) {
setLayoutDirectionFromAnchor();
mWindowManager.updateViewLayout(mDecorView, p);

View File

@@ -24,6 +24,7 @@ import android.app.ActivityManagerNative;
import android.app.SearchManager;
import android.os.UserHandle;
import android.text.TextUtils;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.IRotationWatcher.Stub;
@@ -514,6 +515,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mDecorContentParent.setWindowTitle(title);
}
mTitle = title;
WindowManager.LayoutParams params = getAttributes();
if (!TextUtils.equals(title, params.getTitle())) {
params.setTitle(title);
dispatchWindowAttributesChanged(getAttributes());
}
}
@Override

View File

@@ -3491,6 +3491,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
reportedWindow.setLayer(window.layer);
reportedWindow.setFocused(window.focused);
reportedWindow.setBoundsInScreen(window.boundsInScreen);
reportedWindow.setTitle(window.title);
reportedWindow.setAnchorId(window.accessibilityIdOfAnchor);
final int parentId = findWindowIdLocked(window.parentToken);
if (parentId >= 0) {

View File

@@ -39,6 +39,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
@@ -1213,6 +1214,8 @@ final class AccessibilityController {
window.type = windowState.mAttrs.type;
window.layer = windowState.mLayer;
window.token = windowState.mClient.asBinder();
window.title = windowState.mAttrs.getTitle();
window.accessibilityIdOfAnchor = windowState.mAttrs.accessibilityIdOfAnchor;
WindowState attachedWindow = windowState.mAttachedWindow;
if (attachedWindow != null) {
@@ -1285,6 +1288,12 @@ final class AccessibilityController {
&& !oldWindow.childTokens.equals(newWindow.childTokens)) {
return true;
}
if (!TextUtils.equals(oldWindow.title, newWindow.title)) {
return true;
}
if (oldWindow.accessibilityIdOfAnchor != newWindow.accessibilityIdOfAnchor) {
return true;
}
return false;
}