feat: 增加长按功能

This commit is contained in:
2026-07-14 12:55:47 +08:00
parent 5228188579
commit 2fdf3c3b9e
4 changed files with 76 additions and 6 deletions

View File

@@ -123,6 +123,11 @@ public class MainActivity extends AppCompatActivity {
public void onKeyEvent(int keyCode, int action) {
sendKeyCommand(keyCode, action);
}
@Override
public void onLongPress(float relX, float relY) {
sendLongPressCommand(relX, relY);
}
});
updateUI(false);
@@ -244,8 +249,9 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onDisconnected() {
runOnUiThread(() -> {
Toast.makeText(MainActivity.this, "网络连接已断开", Toast.LENGTH_SHORT).show();
disconnect();
tvStatus.setText("状态: 远端已断开");
updateUI(false);
});
}
});
@@ -327,6 +333,16 @@ public class MainActivity extends AppCompatActivity {
}
}
private void sendLongPressCommand(float relX, float relY) {
if (webRtcClient != null) {
JsonObject cmd = new JsonObject();
cmd.addProperty("action", "LONG_PRESS");
cmd.addProperty("x", relX);
cmd.addProperty("y", relY);
webRtcClient.sendControlCommand(cmd.toString());
}
}
private void disconnect() {
if (webRtcClient != null) {
webRtcClient.close();