栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用AccessibilityService在Android上执行拖动(基于X,Y鼠标坐标)?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用AccessibilityService在Android上执行拖动(基于X,Y鼠标坐标)?

这是一个基于问题Edit 3的解决方案示例。

C#Windows Froms应用程序“ formMain.cs ”:

using System.Net.Sockets;private List<Point> lstPoints;private void pictureBox1_MouseDown(object sender, MouseEventArgs e) {    if (e.Button == MouseButtons.Left)    {        lstPoints = new List<Point>();        lstPoints.Add(new Point(e.X, e.Y));    }}private void PictureBox1_MouseMove(object sender, MouseEventArgs e){    if (e.Button == MouseButtons.Left)    {        lstPoints.Add(new Point(e.X, e.Y));    }}private void PictureBox1_MouseUp(object sender, MouseEventArgs e){    lstPoints.Add(new Point(e.X, e.Y));    StringBuilder sb = new StringBuilder();    foreach (Point obj in lstPoints)    {        sb.Append(Convert.ToString(obj) + ":");    }    serverSocket.Send("MDRAWEVENT" + sb.ToString() + Environment.newline);}

android service ” SocketBackground.java “:

import java.net.Socket;String xline;while (clientSocket.isConnected()) {    BufferedReader xreader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), StandardCharsets.UTF_8));    if (xreader.ready()) {        while ((xline = xreader.readLine()) != null) {     xline = xline.trim(); if (xline != null && !xline.trim().isEmpty()) {     if (xline.contains("MDRAWEVENT")) {         String coordinates = xline.replace("MDRAWEVENT", "");         String[] tokens = coordinates.split(Pattern.quote(":"));         Point[] moviments = new Point[tokens.length];         for (int i = 0; i < tokens.length; i++) { String[] coordinates = tokens[i].replace("{", "").replace("}", "").split(","); int x = Integer.parseInt(coordinates[0].split("=")[1]); int y = Integer.parseInt(coordinates[1].split("=")[1]); moviments[i] = new Point(x, y);         }         MyAccessibilityService.instance.mouseDraw(moviments, 2000);     } }        }    }}

android

AccessibilityService

MyAccessibilityService.java “:

public void mouseDraw(Point[] segments, int time) {    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {        Path path = new Path();        path.moveTo(segments[0].x, segments[0].y);        for (int i = 1; i < segments.length; i++) { path.lineTo(segments[i].x, segments[i].y); GestureDescription.StrokeDescription sd = new GestureDescription.StrokeDescription(path, 0, time); dispatchGesture(new GestureDescription.Builder().addStroke(sd).build(), new AccessibilityService.GestureResultCallback() {     @Override     public void onCompleted(GestureDescription gestureDescription) {         super.onCompleted(gestureDescription);     }     @Override     public void onCancelled(GestureDescription gestureDescription) {         super.onCancelled(gestureDescription);     } }, null);        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429011.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号