feat: 增加长按功能
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user