Commit 1e65d0aa authored by Administrator's avatar Administrator

scroll 优化

parent c0525124
...@@ -99,7 +99,7 @@ public class SwipeUtils { ...@@ -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) { private static void dealSimulateScroll(ViewImage object, float startX, float startY, float endX, float endY, long duration, int period) {
if (isScrolling) { if (isScrolling) {
Log.i(SuperAppium.TAG, "score task is running.."); Log.i(SuperAppium.TAG, "scroll task is running..");
return; return;
} }
isScrolling = true; isScrolling = true;
...@@ -123,6 +123,7 @@ public class SwipeUtils { ...@@ -123,6 +123,7 @@ public class SwipeUtils {
private static MotionEvent genFingerEvent(int action, float x, float y) { 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 downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis();
...@@ -153,6 +154,8 @@ public class SwipeUtils { ...@@ -153,6 +154,8 @@ public class SwipeUtils {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
ViewImage theView = mView.get(); ViewImage theView = mView.get();
if (theView == null) { if (theView == null) {
Log.e(SuperAppium.TAG, "scroll view has bean destroyed");
isScrolling = false;
return; return;
} }
......
...@@ -8,6 +8,7 @@ import android.view.InputEvent; ...@@ -8,6 +8,7 @@ import android.view.InputEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
...@@ -285,6 +286,8 @@ public class ViewImage { ...@@ -285,6 +286,8 @@ public class ViewImage {
EditText editText = (EditText) originView; EditText editText = (EditText) originView;
editText.getText().clear(); editText.getText().clear();
editText.setText(content); editText.setText(content);
//触发焦点到下一个输入框
editText.onEditorAction(EditorInfo.IME_ACTION_NEXT);
return true; return true;
} }
...@@ -394,15 +397,62 @@ public class ViewImage { ...@@ -394,15 +397,62 @@ public class ViewImage {
int toX = (int) (fromX + viewWidth * (ThreadLocalRandom.current().nextDouble(0.1))); int toX = (int) (fromX + viewWidth * (ThreadLocalRandom.current().nextDouble(0.1)));
int fromY = (int) (locs[1] + viewHeight * ThreadLocalRandom.current().nextDouble(0.1)); int fromY, toY;
if (fromY < 2) { if (height > 0) {
fromY = 2; 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); 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) { private MotionEvent genMotionEvent(int action, float[] point) {
long downTime = SystemClock.uptimeMillis(); 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