feat: SystemInputUtils不再处理swipe动作
This commit is contained in:
@@ -79,6 +79,7 @@ public class InputCommandHandler {
|
|||||||
float relY = (float) command.getY();
|
float relY = (float) command.getY();
|
||||||
int x = (int) (relX * screenWidth);
|
int x = (int) (relX * screenWidth);
|
||||||
int y = (int) (relY * screenHeight);
|
int y = (int) (relY * screenHeight);
|
||||||
|
Log.d(TAG, "Motion event: " + action + " at: " + x + ", " + y);
|
||||||
inputExecutor.injectMotionEvent(action, x, y);
|
inputExecutor.injectMotionEvent(action, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,18 +54,18 @@ public class SystemInputUtils implements InputExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectSwipe(int x1, int y1, int x2, int y2, long duration) {
|
public void injectSwipe(int x1, int y1, int x2, int y2, long duration) {
|
||||||
long downTime = SystemClock.uptimeMillis();
|
// long downTime = SystemClock.uptimeMillis();
|
||||||
injectMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, x1, y1);
|
// injectMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, x1, y1);
|
||||||
|
//
|
||||||
int steps = 10;
|
// int steps = 10;
|
||||||
for (int i = 1; i <= steps; i++) {
|
// for (int i = 1; i <= steps; i++) {
|
||||||
SystemClock.sleep(duration / steps);
|
// SystemClock.sleep(duration / steps);
|
||||||
int x = x1 + (x2 - x1) * i / steps;
|
// int x = x1 + (x2 - x1) * i / steps;
|
||||||
int y = y1 + (y2 - y1) * i / steps;
|
// int y = y1 + (y2 - y1) * i / steps;
|
||||||
injectMotionEvent(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y);
|
// injectMotionEvent(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
injectMotionEvent(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x2, y2);
|
// injectMotionEvent(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x2, y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onSwipe(float relX1, float relY1, float relX2, float relY2, long duration) {
|
public void onSwipe(float relX1, float relY1, float relX2, float relY2, long duration) {
|
||||||
// 已通过 onMotionEvent 处理
|
// 已通过 onMotionEvent 处理
|
||||||
|
sendSwipeCommand(relX1, relY1, relX2, relY2, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -589,7 +590,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
Object ms = stats.getMembers().get("messagesSent");
|
Object ms = stats.getMembers().get("messagesSent");
|
||||||
if (ms instanceof Number) dcMessagesSent = ((Number) ms).longValue();
|
if (ms instanceof Number) dcMessagesSent = ((Number) ms).longValue();
|
||||||
Object mr = stats.getMembers().get("messagesReceived");
|
Object mr = stats.getMembers().get("messagesReceived");
|
||||||
if (mr instanceof Number) dcMessagesReceived = ((Number) mr).longValue();
|
if (mr instanceof Number)
|
||||||
|
dcMessagesReceived = ((Number) mr).longValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -650,8 +652,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// 依据选定候选对的本地/远端候选类型,返回 P2P / TURN 中继描述。
|
// 依据选定候选对的本地/远端候选类型,返回 P2P / TURN 中继描述。
|
||||||
private String resolveConnectionType(org.webrtc.RTCStatsReport report,
|
private String resolveConnectionType(org.webrtc.RTCStatsReport report,
|
||||||
String localCandidateId,
|
String localCandidateId,
|
||||||
String remoteCandidateId) {
|
String remoteCandidateId) {
|
||||||
String local = candidateTypeOf(report, localCandidateId);
|
String local = candidateTypeOf(report, localCandidateId);
|
||||||
String remote = candidateTypeOf(report, remoteCandidateId);
|
String remote = candidateTypeOf(report, remoteCandidateId);
|
||||||
boolean isRelay = "relay".equals(local) || "relay".equals(remote);
|
boolean isRelay = "relay".equals(local) || "relay".equals(remote);
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class RemoteTouchView extends SurfaceView {
|
|||||||
public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
|
public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onKeyEvent(keyCode, android.view.KeyEvent.ACTION_DOWN);
|
listener.onKeyEvent(keyCode, android.view.KeyEvent.ACTION_DOWN);
|
||||||
|
Log.d(TAG, "KeyDown: " + keyCode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
@@ -87,6 +88,7 @@ public class RemoteTouchView extends SurfaceView {
|
|||||||
public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
|
public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onKeyEvent(keyCode, android.view.KeyEvent.ACTION_UP);
|
listener.onKeyEvent(keyCode, android.view.KeyEvent.ACTION_UP);
|
||||||
|
Log.d(TAG, "KeyUp: " + keyCode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onKeyUp(keyCode, event);
|
return super.onKeyUp(keyCode, event);
|
||||||
@@ -111,6 +113,7 @@ public class RemoteTouchView extends SurfaceView {
|
|||||||
|
|
||||||
// 发送原始 MotionEvent 实现实时跟手
|
// 发送原始 MotionEvent 实现实时跟手
|
||||||
listener.onMotionEvent(action, relX, relY);
|
listener.onMotionEvent(action, relX, relY);
|
||||||
|
Log.d(TAG, "MotionEvent: " + action + ", " + relX + ", " + relY);
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
@@ -134,8 +137,10 @@ public class RemoteTouchView extends SurfaceView {
|
|||||||
// 保留旧的回调以防万一,但 MainActivity 现在应该忽略它们
|
// 保留旧的回调以防万一,但 MainActivity 现在应该忽略它们
|
||||||
if (duration < 200 && dx < 0.02 && dy < 0.02) {
|
if (duration < 200 && dx < 0.02 && dy < 0.02) {
|
||||||
listener.onTouch(lastTouchX, lastTouchY);
|
listener.onTouch(lastTouchX, lastTouchY);
|
||||||
|
Log.d(TAG, "Touch at: " + lastTouchX + ", " + lastTouchY);
|
||||||
} else {
|
} else {
|
||||||
listener.onSwipe(lastTouchX, lastTouchY, relX, relY, duration);
|
listener.onSwipe(lastTouchX, lastTouchY, relX, relY, duration);
|
||||||
|
Log.d(TAG, "Swipe from: " + lastTouchX + ", " + lastTouchY + " to: " + relX + ", " + relY + " duration: " + duration);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user