Commit 1e65d0aa authored by Administrator's avatar Administrator

scroll 优化

parent c0525124
......@@ -99,7 +99,7 @@ public class SwipeUtils {
private static void dealSimulateScroll(ViewImage object, float startX, float startY, float endX, float endY, long duration, int period) {
if (isScrolling) {
Log.i(SuperAppium.TAG, "score task is running..");
Log.i(SuperAppium.TAG, "scroll task is running..");
return;
}
isScrolling = true;
......@@ -123,6 +123,7 @@ public class SwipeUtils {
private static MotionEvent genFingerEvent(int action, float x, float y) {
// Log.i("HD_HOOK", "genFingerEvent action: " + action + " point:(" + x + " , " + y + ")");
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
......@@ -153,6 +154,8 @@ public class SwipeUtils {
public void handleMessage(Message msg) {
ViewImage theView = mView.get();
if (theView == null) {
Log.e(SuperAppium.TAG, "scroll view has bean destroyed");
isScrolling = false;
return;
}
......
......@@ -8,6 +8,7 @@ import android.view.InputEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.EditText;
......@@ -285,6 +286,8 @@ public class ViewImage {
EditText editText = (EditText) originView;
editText.getText().clear();
editText.setText(content);
//触发焦点到下一个输入框
editText.onEditorAction(EditorInfo.IME_ACTION_NEXT);
return true;
}
......@@ -394,15 +397,62 @@ public class ViewImage {
int toX = (int) (fromX + viewWidth * (ThreadLocalRandom.current().nextDouble(0.1)));
int fromY = (int) (locs[1] + viewHeight * ThreadLocalRandom.current().nextDouble(0.1));
if (fromY < 2) {
fromY = 2;
int fromY, toY;
if (height > 0) {
fromY = (int) (locs[1] + viewHeight * ThreadLocalRandom.current().nextDouble(0.1));
if (fromY < 2) {
fromY = 2;
}
toY = fromY + height;
} else {
fromY = (int) (locs[1] + viewHeight * (ThreadLocalRandom.current().nextDouble(0.1) + 0.9));
toY = fromY + height;
if (toY < 2) {
toY = 2;
}
}
int toY = fromY + height;
SwipeUtils.simulateScroll(this, fromX, fromY, toX, toY, 400, 50);
}
/**
* 向右滑动
*
* @param width 滑动宽度,如果为负数,则向左滑动
*/
@SuppressLint("NewApi")
public void swipeRight(int width) {
int[] locs = new int[2];
originView.getLocationOnScreen(locs);
int viewWidth = originView.getWidth();
int viewHeight = originView.getHeight();
int fromY = (int) (locs[1] + viewHeight * (ThreadLocalRandom.current().nextDouble(0.05) - 0.025 + 0.5));
if (fromY < 2) {
fromY = 2;
}
int toY = (int) (fromY + viewHeight * (ThreadLocalRandom.current().nextDouble(0.008)));
int fromX, toX;
if (width > 0) {
fromX = (int) (locs[0] + viewWidth * ThreadLocalRandom.current().nextDouble(0.1));
if (fromX < 2) {
fromX = 2;
}
toX = fromX + width;
} else {
fromX = (int) (locs[0] + viewWidth * (ThreadLocalRandom.current().nextDouble(0.1) + 0.9));
toX = fromX + width;
if (toX < 2) {
toX = 2;
}
}
// Log.i(SuperAppium.TAG, "location on screen: (" + locs[0] + "," + locs[1] + ") from loc:("
// + fromX + "," + fromY + ") to loc:(" + toX + "," + toY + ") with and height: (" + viewWidth + "," + viewHeight + ")");
SwipeUtils.simulateScroll(this, fromX, fromY, toX, toY, 300, 50);
}
private MotionEvent genMotionEvent(int action, float[] point) {
long downTime = SystemClock.uptimeMillis();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment