- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试使用以下代码执行点击,但是 here说存在一些限制,我可以在我的测试中看到这一点。
但似乎这个错误是因为 Rect()
不包含 X, Y 坐标引起的,为什么每次我点击一个地方在不支持的地方(可能有一些限制,就像在示例的自述文件中所说的那样)在 findSmallestNodeAtPoint()
例程中的这一行执行:
if (!bounds.contains(x, y)) {
System.out.println("ERROR DETECTED!!! :::::: NOT bounds.contains(x, y) :::::::");
return null;
}
Here在这个问题中,也提到了 Github 的这个例子,并给出了一个代码示例的答案,该代码示例 100%(测试)来自 android Nougat+(api 24 及更高版本),但在我的情况下,我还需要将下面的代码修复到我的应用程序支持在旧版本的android中执行点击。
然后已经知道这段代码在哪里失败了,我想知道可以做些什么:
!bounds.contains(x, y)
代码的主要部分是:
private static void logNodeHierachy(AccessibilityNodeInfo nodeInfo, int depth) {
Rect bounds = new Rect();
nodeInfo.getBoundsInScreen(bounds);
StringBuilder sb = new StringBuilder();
if (depth > 0) {
for (int i=0; i<depth; i++) {
sb.append(" ");
}
sb.append("\u2514 ");
}
sb.append(nodeInfo.getClassName());
sb.append(" (" + nodeInfo.getChildCount() + ")");
sb.append(" " + bounds.toString());
if (nodeInfo.getText() != null) {
sb.append(" - \"" + nodeInfo.getText() + "\"");
}
System.out.println(sb.toString());
for (int i=0; i<nodeInfo.getChildCount(); i++) {
AccessibilityNodeInfo childNode = nodeInfo.getChild(i);
if (childNode != null) {
logNodeHierachy(childNode, depth + 1);
}
}
}
private static AccessibilityNodeInfo findSmallestNodeAtPoint(AccessibilityNodeInfo sourceNode, int x, int y) {
Rect bounds = new Rect();
sourceNode.getBoundsInScreen(bounds);
if (!bounds.contains(x, y)) {
System.out.println(":::::: NOT bounds.contains(x, y) :::::::");
return null;
}
for (int i=0; i<sourceNode.getChildCount(); i++) {
AccessibilityNodeInfo nearestSmaller = findSmallestNodeAtPoint(sourceNode.getChild(i), x, y);
if (nearestSmaller != null) {
return nearestSmaller;
}
}
return sourceNode;
}
public void click(int x, int y) {
System.out.println(String.format("Click [%d, %d]", x, y));
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) return;
AccessibilityNodeInfo nearestNodeToMouse = findSmallestNodeAtPoint(nodeInfo, x, y);
if (nearestNodeToMouse != null) {
logNodeHierachy(nearestNodeToMouse, 0);
nearestNodeToMouse.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
nodeInfo.recycle();
}
最佳答案
好吧,我回答我自己的问题,AccessibilityService
的专家已经认为我正在构建恶意软件而不是帮助这类人。
显然似乎不可能使用基于 this 的 Rect()
和 getBoundsInScreen()
进行转义回答。
我还发现了另一个类似的代码,ref :
public void click(int x, int y) {
clickAtPosition(x, y, getRootInActiveWindow());
}
public static void clickAtPosition(int x, int y, AccessibilityNodeInfo node) {
if (node == null) return;
if (node.getChildCount() == 0) {
Rect buttonRect = new Rect();
node.getBoundsInScreen(buttonRect);
if (buttonRect.contains(x, y)) {
// Maybe we need to think if a large view covers item?
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
System.out.println("1º - Node Information: " + node.toString());
}
} else {
Rect buttonRect = new Rect();
node.getBoundsInScreen(buttonRect);
if (buttonRect.contains(x, y)) {
// Maybe we need to think if a large view covers item?
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
System.out.println("2º - Node Information: " + node.toString());
}
for (int i = 0; i < node.getChildCount(); i++) {
clickAtPosition(x, y, node.getChild(i));
}
}
}
也有麻烦。但是比上面问题链接的代码更好:D。
在我的测试中,只有在 android 虚拟键盘上无法执行点击。
关于java - AccessibilityNodeInfo in getRoot ActiveWindow : Perform click fails with Rect() not contains X, Y坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52022519/
好的,所以我有一个自定义的 rect 函数。自定义rect如下: typedef struct tagRECTEx{ // long left; // long top; // long right;
我在 Rectangles 上找到了这个很棒的数学运算文件: https://gist.github.com/Noitidart/90ea1ebd30156df9ef530c6a9a1b6ea7 及其
在我的 onDraw 中,我拥有构建整个 View 所需的所有代码,但我如何检测我是否只想执行部分重绘。我想应该通过调用 canvas.invalidate(Rect rect); 来触发部分重绘。正
我对以下游戏 map 有疑问: 我想把所有的陆地区域(黄色附近)保存在一个数组中,这样计算机以后就知道用户的点击是在水面上(鼠标指针的x/y坐标不在数组中)还是在国内(x/y 坐标光标不在数组中)。我
我尝试制作一个简单的可视化列,其中矩形的高度由比例确定: var heightScale = d3.scaleLinear() .domain([150,2500]) .range([
我在 WPF 中有一个小项目,我需要在其中交换 UIElement。类似于 iGoogle 的功能。 由于我发不了图片(信誉不够)我会用文字说明。我有一个这样定义的 3x3 网格: 0 1
这个问题已经有答案了: How do I detect collision in pygame? (5 个回答) 已关闭 6 个月前。 问候, 我在 pygame 中从事的项目似乎遇到了一些麻烦。对于
我正在使用: check = pygame.image.load("check.png") checkrect = check.get_rect() checkrect = checkrect.mov
我试图让我的玩家 rect 在侧面和底部与我的敌人 rect 碰撞,因此玩家 rect 不会抛出敌人的 rect 但我不知道为什么它一直将我传送到它根本不起作用 VIDEo platform.rec
这个问题已经有答案了: How do I get the snake to grow and chain the movement of the snake's body? (1 个回答) 已关闭 3
API 是否应该提供 Rect::contains(Point) 或 Point::is_inside(Rect) 或两者? 或 Math::contains(Point, Rect) 因为它是对称的
我在我的项目中使用 Konva.js,我特别需要在使用 Konva.Rect() 类定义的可拖动矩形内定义文本。有没有一种方法可以在不使用单独的 Konva.Text 的情况下实现这一点() 或 Ko
'annot' CGPDFDictionary 'Rect' 如何转换为 objective-c Rect: 最佳答案 Adobes PDF Spec状态: Rectangles are used t
我正在尝试在 UIView 中绘制一个字符串。 class ViewController: UIViewController { override func viewDidLoad() { s
我正在使用 D3 制作图表。我希望用户能够通过调整单列水平柱形图上堆叠条形的大小来输入他们的选择。 条形堆叠在一起,每个条形都有 .call(drag) 事件监听器。 此拖动事件返回错误。 var d
我刚刚在官方文档中浏览了 pygame 的 .rect 方法。 我们有2个案例, pygame.rect.move(arg1,arg2) 用于在屏幕上移动 .rect 对象 和 pygame.rect
所以我尝试使用实例为我的游戏进行碰撞检测。代码如下: class Paddle: def __init__(self, x, y, width, height, rect): self.x =
我是否正确使用了drawPixmap()? 本质上,我的目标是拍摄一张图 block 图像,然后用自定义图 block 图像替换单个图 block 。 我能够将两个图像都加载到屏幕上,但是当我调用 d
这个想法很简单:我有一个 SVG 路径和一个 Rect,我需要让路径穿过矩形,由此产生的“洞”应该是透明的。 这是 jsfiddle,其中包含一份它现在的样子: https://jsfiddle.ne
很抱歉问了一个菜鸟问题,但是有人能告诉我这两者之间的区别吗 cv:: Rect rect; int width = rect.width; int height = rect.height; 还有这个
我是一名优秀的程序员,十分优秀!