Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed endless scroll bug + ghost clicks bug + latency issues #67

Open
wants to merge 3 commits into
base: test-adb-server
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.view.InputEvent;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityWindowInfo;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -28,9 +27,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -42,7 +38,6 @@
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;

import io.github.virresh.matvt.helper.Helper;
import io.github.virresh.matvt.services.MouseEventService;
import io.github.virresh.matvt.view.MouseCursorView;
import io.github.virresh.matvt.view.OverlayView;
Expand All @@ -56,6 +51,10 @@ public class MouseEmulationEngine {

CountDownTimer disappearTimer;

CountDownTimer swipeGestureCoolDown;

private boolean isQueueEmpty = true;

private boolean isInScrollMode = false;

// service which started this engine
Expand Down Expand Up @@ -185,7 +184,7 @@ public void run() {
mPointerControl.reappear();
// mService.dispatchGesture(createSwipe(originPoint, direction, 20 + momentumStack), null, null);
createSwipe(originPoint, direction, 20 + momentumStack);
momentumStack += 1;
//momentumStack += 1;
timerHandler.postDelayed(this, 30);
}
};
Expand All @@ -202,7 +201,7 @@ public void run() {
mPointerControl.reappear();
// mService.dispatchGesture(createSwipe(originPoint, direction, 20 + momentumStack), null, null);
createSwipe(originPoint, direction, 20 + momentumStack);
momentumStack += 1;
//momentumStack += 1;
timerHandler.postDelayed(this, 30);
}
};
Expand Down Expand Up @@ -246,20 +245,38 @@ private static GestureDescription createClick (PointF clickPoint, long duration)
return clickBuilder.build();
}

private GestureDescription createSwipe (PointF originPoint, int direction, int momentum) {
final int DURATION = scrollSpeed + 20;
Path clickPath = new Path();
PointF lineDirection = new PointF(originPoint.x + (momentum + 75) * PointerControl.dirX[direction], originPoint.y + (momentum + 75) * PointerControl.dirY[direction]);
private void createSwipe (PointF originPoint, int direction, int momentum) {

if(!isQueueEmpty) return;

isQueueEmpty = false;

final int DURATION = 300 - scrollSpeed*10;
Path clickPath = new Path();
PointF lineDirection = new PointF(originPoint.x + (75 + momentum) * PointerControl.dirX[direction], originPoint.y + (75+momentum) * PointerControl.dirY[direction]);
mService.shellSwipe((int) originPoint.x, (int) originPoint.y, (int) lineDirection.x, (int) lineDirection.y, DURATION);

clickPath.moveTo(originPoint.x, originPoint.y);
clickPath.lineTo(lineDirection.x, lineDirection.y);
GestureDescription.StrokeDescription clickStroke =
new GestureDescription.StrokeDescription(clickPath, 0, DURATION);
GestureDescription.Builder clickBuilder = new GestureDescription.Builder();
clickBuilder.addStroke(clickStroke);
return clickBuilder.build();
swipeGestureCoolDown = new CountDownTimer(DURATION+200,100) {
@Override
public void onTick(long millisUntilFinished) {}
@Override
public void onFinish() {
isQueueEmpty = true;
}
};

swipeGestureCoolDown.start();

momentumStack += 1;

/*
try {
Thread.sleep(DURATION + 200);
} catch (InterruptedException e) {
Log.e(LOG_TAG, "Thread interrupted: ",e);
}
*/

}

public boolean perform (KeyEvent keyEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {

// don't like to advertise in the product, but need to mention here
// need to increase visibility of the open source version
gui_about.setText("MATVT v" + BuildConfig.VERSION_NAME + "\nThis is an open source project. It's available for free and will always be. If you find issues / would like to help in improving this project, please contribute at \nhttps://github.com/virresh/matvt");
gui_about.setText("MATVT v" + BuildConfig.VERSION_NAME + "\n\nThis is an open source project. It's available for free and will always be. If you find issues / would like to help in improving this project, please contribute at \nhttps://github.com/virresh/matvt");

// render icon style dropdown
IconStyleSpinnerAdapter iconStyleSpinnerAdapter = new IconStyleSpinnerAdapter(this, R.layout.spinner_icon_text_gui, R.id.textView, IconStyleSpinnerAdapter.getResourceList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void shellSwipe(Integer x1, Integer y1, Integer x2, Integer y2, Integer d
// Log.i(TAG_NAME, "Succeeded ? ===> " + response.isSuccessful());
// }
// });
sendShellInput("swipe " + x1.toString() + " " + y1.toString() + " " + x2.toString() + " " + y2.toString());
sendShellInput("swipe " + x1.toString() + " " + y1.toString() + " " + x2.toString() + " " + y2.toString() + " " + duration.toString());
}

public void shellTap(Integer x, Integer y) {
Expand Down