Skip to content

Commit

Permalink
修复不同分辨率设备没有应用正确的缩放比例
Browse files Browse the repository at this point in the history
  • Loading branch information
harry committed Jun 22, 2017
1 parent ace27d0 commit 7709449
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/yeetor/androidcontrol/DeviceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alibaba.fastjson.annotation.JSONField;
import com.android.ddmlib.IDevice;
import com.yeetor.adb.AdbServer;

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

sn = device.getSerialNumber();

// String str = AdbServer.executeShellCommand(device, "wm size");
// if (str != null && !str.isEmpty()) {
// String[] sizeStr = str.split(":")[1].split("x");
// width = Integer.parseInt(sizeStr[0].trim());
// height = Integer.parseInt(sizeStr[1].trim());
// }
String str = AdbServer.server().executeShellCommand(device, "wm size");
if (str != null && !str.isEmpty()) {
String[] sizeStr = str.split(":")[1].split("x");
width = Integer.parseInt(sizeStr[0].trim());
height = Integer.parseInt(sizeStr[1].trim());
}

// brand = device.getProperty("ro.product.brand");
// model = device.getProperty("ro.product.model");
Expand Down
15 changes: 10 additions & 5 deletions web/js/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var util = {
getMinicapRotate:function () {
return localStorage.getItem("minicap_rotate");
},
isRotate: false
isRotate: false,
screenW:400,
screenH:400
};
var webSocket = null;

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

util.screenW = getUrlParams("w") || 1080;
util.screenH = getUrlParams("h") || 1920;

$("#minicapScaleText").val(util.getMinicapScale());

var s = util.getMinicapRotate();
Expand Down Expand Up @@ -320,8 +325,8 @@ function sendKeyEvent(keyevent) {
}

function sendDown(argx, argy, isRo) {
var scalex = 1080.0 / canvas.width;
var scaley = 1920.0 / canvas.height;
var scalex = util.screenW / canvas.width;
var scaley = util.screenH / canvas.height;
var x = argx, y = argy;
if (isRo) {
x = (canvas.height - argy) * (canvas.width / canvas.height);
Expand All @@ -335,8 +340,8 @@ function sendDown(argx, argy, isRo) {
}

function sendMove(argx, argy, isRo) {
var scalex = 1080.0 / canvas.width;
var scaley = 1920.0 / canvas.height;
var scalex = util.screenW / canvas.width;
var scaley = util.screenH / canvas.height;
var x = argx, y = argy;
if (isRo) {
x = (canvas.height - argy) * (canvas.width / canvas.height);
Expand Down
8 changes: 4 additions & 4 deletions web/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function requestDevices() {
};
}

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

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

0 comments on commit 7709449

Please sign in to comment.