Skip to content

Commit 7709449

Browse files
author
harry
committed
修复不同分辨率设备没有应用正确的缩放比例
1 parent ace27d0 commit 7709449

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

‎src/main/java/com/yeetor/androidcontrol/DeviceInfo.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.alibaba.fastjson.annotation.JSONField;
44
import com.android.ddmlib.IDevice;
5+
import com.yeetor.adb.AdbServer;
56

67
/**
78
* Created by harry on 2017/4/21.
@@ -21,12 +22,12 @@ public DeviceInfo(IDevice device) {
2122

2223
sn = device.getSerialNumber();
2324

24-
// String str = AdbServer.executeShellCommand(device, "wm size");
25-
// if (str != null && !str.isEmpty()) {
26-
// String[] sizeStr = str.split(":")[1].split("x");
27-
// width = Integer.parseInt(sizeStr[0].trim());
28-
// height = Integer.parseInt(sizeStr[1].trim());
29-
// }
25+
String str = AdbServer.server().executeShellCommand(device, "wm size");
26+
if (str != null && !str.isEmpty()) {
27+
String[] sizeStr = str.split(":")[1].split("x");
28+
width = Integer.parseInt(sizeStr[0].trim());
29+
height = Integer.parseInt(sizeStr[1].trim());
30+
}
3031

3132
// brand = device.getProperty("ro.product.brand");
3233
// model = device.getProperty("ro.product.model");

‎web/js/device.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ var util = {
1616
getMinicapRotate:function () {
1717
return localStorage.getItem("minicap_rotate");
1818
},
19-
isRotate: false
19+
isRotate: false,
20+
screenW:400,
21+
screenH:400
2022
};
2123
var webSocket = null;
2224

@@ -90,6 +92,9 @@ window.onload = function() {
9092
util.ip = getUrlParams("ip") || "127.0.0.1";
9193
util.port = getUrlParams("port") || "6655";
9294

95+
util.screenW = getUrlParams("w") || 1080;
96+
util.screenH = getUrlParams("h") || 1920;
97+
9398
$("#minicapScaleText").val(util.getMinicapScale());
9499

95100
var s = util.getMinicapRotate();
@@ -320,8 +325,8 @@ function sendKeyEvent(keyevent) {
320325
}
321326

322327
function sendDown(argx, argy, isRo) {
323-
var scalex = 1080.0 / canvas.width;
324-
var scaley = 1920.0 / canvas.height;
328+
var scalex = util.screenW / canvas.width;
329+
var scaley = util.screenH / canvas.height;
325330
var x = argx, y = argy;
326331
if (isRo) {
327332
x = (canvas.height - argy) * (canvas.width / canvas.height);
@@ -335,8 +340,8 @@ function sendDown(argx, argy, isRo) {
335340
}
336341

337342
function sendMove(argx, argy, isRo) {
338-
var scalex = 1080.0 / canvas.width;
339-
var scaley = 1920.0 / canvas.height;
343+
var scalex = util.screenW / canvas.width;
344+
var scaley = util.screenH / canvas.height;
340345
var x = argx, y = argy;
341346
if (isRo) {
342347
x = (canvas.height - argy) * (canvas.width / canvas.height);

‎web/js/index.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function requestDevices() {
2222
};
2323
}
2424

25-
function onDeviceClick(sn) {
26-
window.open("device.html?sn=" + sn);
25+
function onDeviceClick(sn, w, h) {
26+
window.open("device.html?sn=" + sn + "&w=" + w + "&h=" + h);
2727
};
2828

2929
/**
@@ -36,8 +36,8 @@ var fillDevices = function(array) {
3636
var deviceInfo = array[i];
3737
var innerCanvas = "";
3838
var html = "<div class='col-lg-2 col-md-3 col-sm-3 col-xs-6 device-container'>" +
39-
"<img class='' src='" + "http://" + server.getServerIp() + ":" + server.getServerPort() + "/shot/" + deviceInfo.sn + "' onclick='onDeviceClick(\"" + deviceInfo.sn + "\")' />" +
40-
"<div class='device-detail'><sapn>" + deviceInfo.sn + "</sapn></div>" +
39+
"<img class='' src='" + "http://" + server.getServerIp() + ":" + server.getServerPort() + "/shot/" + deviceInfo.sn + "' onclick='onDeviceClick(\"" + deviceInfo.sn + "\", " + deviceInfo.w + "," + deviceInfo.h + ")' />" +
40+
"<div class='device-detail'><sapn>" + deviceInfo.sn + "</sapn><br><span>@" + deviceInfo.w + "x" + deviceInfo.h + "</span></div>" +
4141
"</div>";
4242
var dom = $(html);
4343
$(".container-fluid .row").append(dom);

0 commit comments

Comments
 (0)