Skip to content

Commit

Permalink
fix click on infinitly display always return false error
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Feb 20, 2020
1 parent adc1795 commit ef183e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public interface AutomatorService {
*/
boolean click(int x, int y);

/**
* Perform a click at arbitrary coordinates specified by the user
*
* @param x
* @param y
* @param milliseconds
* @return
*/
public boolean click(int x, int y, long milliseconds);

/**
* Performs a swipe from one coordinate to another coordinate. You can control the smoothness and speed of the swipe by specifying the number of steps. Each step execution is throttled to 5 milliseconds per step, so for a 100 steps, the swipe will take around 0.5 seconds to complete.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.Configurator;
import android.support.test.uiautomator.Direction;
Expand Down Expand Up @@ -196,9 +197,25 @@ public boolean clearLastToast() {
*/
@Override
public boolean click(int x, int y) {
return device.click(x, y);
// The original implementation got bug here.
// when y >= getDiaplayHeight() return false, but getDisplayHeight() is not right in infinity display
// return device.click(x, y);
if (x < 0 || y < 0){
return false;
}
touchController.touchDown(x, y);
SystemClock.sleep(100); // normally 100ms for click
return touchController.touchUp(x, y);
}

public boolean click(int x, int y, long milliseconds) {
if (x < 0 || y < 0){
return false;
}
touchController.touchDown(x, y);
SystemClock.sleep(milliseconds);
return touchController.touchUp(x, y);
}
/**
* Performs a swipe from one coordinate to another coordinate. You can control the smoothness and speed of the swipe by specifying the number of steps. Each step execution is throttled to 5 milliseconds per step, so for a 100 steps, the swipe will take around 0.5 seconds to complete.
*
Expand Down

0 comments on commit ef183e8

Please sign in to comment.