Skip to content

Commit a61f5f6

Browse files
committed
自动化 UI 测试:完成横纵两条分割线及适配横屏
1 parent b8c92e4 commit a61f5f6

File tree

10 files changed

+446
-235
lines changed

10 files changed

+446
-235
lines changed

APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/application/DemoApplication.java

Lines changed: 270 additions & 100 deletions
Large diffs are not rendered by default.

APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/ui/SelectActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
265265
}
266266
}
267267

268-
268+
@Override
269+
protected void onDestroy() {
270+
DemoApplication.getInstance().onUIAutoActivityDestroy(this);
271+
super.onDestroy();
272+
}
269273
}

APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/ui/UIAutoActivity.java

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
*/
4141
public class UIAutoActivity extends Activity {
4242
private static final String TAG = "UIAutoActivity";
43-
private static final String DIVIDER_Y = "DIVIDER_Y";
44-
private static final String DIVIDER_HEIGHT = "DIVIDER_HEIGHT";
45-
private static final String DIVIDER_COLOR = "DIVIDER_COLOR";
43+
private static final String SPLIT_Y = "SPLIT_Y";
44+
private static final String SPLIT_HEIGHT = "SPLIT_HEIGHT";
45+
private static final String SPLIT_COLOR = "SPLIT_COLOR";
4646

4747
private static final String INTENT_FLOW_ID = "INTENT_FLOW_ID";
4848
private static final String INTENT_TOUCH_LIST = "INTENT_TOUCH_LIST";
@@ -73,7 +73,7 @@ public static Intent createIntent(Context context, String list) {
7373
// //通过遍历数组来实现
7474
//// if (lastCurTime >= System.currentTimeMillis()) {
7575
//// isRecovering = false;
76-
//// pbUIAutoDivider.setVisibility(View.GONE);
76+
//// pbUIAutoSplit.setVisibility(View.GONE);
7777
//// }
7878
////
7979
//// MotionEvent event = (MotionEvent) msg.obj;
@@ -86,7 +86,7 @@ public static Intent createIntent(Context context, String list) {
8686
//
8787
// if (eventNode.next == null) {
8888
// isRecovering = false;
89-
// pbUIAutoDivider.setVisibility(View.GONE);
89+
// pbUIAutoSplit.setVisibility(View.GONE);
9090
// return;
9191
// }
9292
//
@@ -106,14 +106,14 @@ public static Intent createIntent(Context context, String list) {
106106
// int windowY;
107107
//
108108
// ViewGroup cover;
109-
// ViewGroup divider;
110-
// View rlUIAutoDivider;
111-
// View vUIAutoDivider;
112-
// View ivUIAutoDivider;
113-
// View pbUIAutoDivider;
114-
//
115-
// private float dividerY;
116-
// private float dividerHeight;
109+
// ViewGroup split;
110+
// View rlUIAutoSplitY;
111+
// View vUIAutoSplit;
112+
// View ivUIAutoSplit;
113+
// View pbUIAutoSplit;
114+
//
115+
// private float splitY;
116+
// private float splitHeight;
117117
// private boolean moved = false;
118118

119119
private JSONArray touchList;
@@ -148,11 +148,11 @@ protected void onCreate(Bundle savedInstanceState) {
148148
//
149149
// cache = getSharedPreferences(TAG, Context.MODE_PRIVATE);
150150
//
151-
// dividerY = cache.getFloat(DIVIDER_Y, 0);
152-
// dividerHeight = cache.getFloat(DIVIDER_HEIGHT, dip2px(24));
151+
// splitY = cache.getFloat(SPLIT_Y, 0);
152+
// splitHeight = cache.getFloat(SPLIT_HEIGHT, dip2px(24));
153153
//
154-
// if (dividerY <= dividerHeight || dividerY >= windowHeight - dividerHeight) {
155-
// dividerY = windowHeight - dividerHeight - dip2px(30);
154+
// if (splitY <= splitHeight || splitY >= windowHeight - splitHeight) {
155+
// splitY = windowHeight - splitHeight - dip2px(30);
156156
// }
157157

158158
if (touchList != null && touchList.isEmpty() == false) { //TODO 回放操作
@@ -164,43 +164,43 @@ protected void onCreate(Bundle savedInstanceState) {
164164

165165
// ViewGroup root = (ViewGroup) getWindow().getDecorView();
166166
// cover = (ViewGroup) getLayoutInflater().inflate(R.layout.ui_auto_cover_layout, null);
167-
// divider = (ViewGroup) getLayoutInflater().inflate(R.layout.ui_auto_divider_layout, null);
167+
// split = (ViewGroup) getLayoutInflater().inflate(R.layout.ui_auto_split_y_layout, null);
168168
//
169-
// rlUIAutoDivider = divider.findViewById(R.id.rlUIAutoDivider);
170-
// vUIAutoDivider = divider.findViewById(R.id.vUIAutoDivider);
171-
// ivUIAutoDivider = divider.findViewById(R.id.ivUIAutoDivider);
172-
// pbUIAutoDivider = divider.findViewById(R.id.pbUIAutoDivider);
173-
// pbUIAutoDivider.setVisibility(View.GONE);
169+
// rlUIAutoSplitY = split.findViewById(R.id.rlUIAutoSplitY);
170+
// vUIAutoSplit = split.findViewById(R.id.vUIAutoSplit);
171+
// ivUIAutoSplit = split.findViewById(R.id.ivUIAutoSplit);
172+
// pbUIAutoSplit = split.findViewById(R.id.pbUIAutoSplit);
173+
// pbUIAutoSplit.setVisibility(View.GONE);
174174
//
175-
// ViewGroup.LayoutParams dividerLp = rlUIAutoDivider.getLayoutParams();
176-
// if (dividerLp == null) {
177-
// dividerLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) dividerHeight);
175+
// ViewGroup.LayoutParams splitLp = rlUIAutoSplitY.getLayoutParams();
176+
// if (splitLp == null) {
177+
// splitLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) splitHeight);
178178
// } else {
179-
// dividerLp.height = (int) dividerHeight;
179+
// splitLp.height = (int) splitHeight;
180180
// }
181-
// rlUIAutoDivider.setLayoutParams(dividerLp);
181+
// rlUIAutoSplitY.setLayoutParams(splitLp);
182182
//
183-
//// cover.addView(divider);
183+
//// cover.addView(split);
184184
//
185-
//// rlUIAutoDivider.post(new Runnable() {
185+
//// rlUIAutoSplitY.post(new Runnable() {
186186
//// @Override
187187
//// public void run() {
188-
//// rlUIAutoDivider.setY(dividerY - rlUIAutoDivider.getHeight()/2);
188+
//// rlUIAutoSplitY.setY(splitY - rlUIAutoSplitY.getHeight()/2);
189189
//// cover.setVisibility(View.GONE);
190190
//// }
191191
//// });
192192
//
193-
// vUIAutoDivider.setBackgroundColor(Color.parseColor(cache.getString(DIVIDER_COLOR, "#10000000")));
193+
// vUIAutoSplit.setBackgroundColor(Color.parseColor(cache.getString(SPLIT_COLOR, "#10000000")));
194194
//
195-
// ViewGroup.LayoutParams lineLp = ivUIAutoDivider.getLayoutParams();
195+
// ViewGroup.LayoutParams lineLp = ivUIAutoSplit.getLayoutParams();
196196
// if (lineLp == null) {
197-
// lineLp = new RelativeLayout.LayoutParams((int) dividerHeight, (int) dividerHeight);
197+
// lineLp = new RelativeLayout.LayoutParams((int) splitHeight, (int) splitHeight);
198198
// } else {
199-
// lineLp.width = lineLp.height = (int) dividerHeight;
199+
// lineLp.width = lineLp.height = (int) splitHeight;
200200
// }
201-
// ivUIAutoDivider.setLayoutParams(lineLp);
201+
// ivUIAutoSplit.setLayoutParams(lineLp);
202202
//
203-
// ivUIAutoDivider.setOnClickListener(new View.OnClickListener() {
203+
// ivUIAutoSplit.setOnClickListener(new View.OnClickListener() {
204204
// @Override
205205
// public void onClick(View v) {
206206
// isRecovering = false;
@@ -223,26 +223,26 @@ protected void onCreate(Bundle savedInstanceState) {
223223
// startActivity(UIAutoActivity.createIntent(DemoApplication.getInstance(), touchList == null ? null : touchList.toJSONString()));
224224
//
225225
// floatCover = null;
226-
// floatDivider = null;
226+
// floatSplitY = null;
227227
// FloatWindow.destroy("v");
228228
// FloatWindow.destroy("v_ball");
229229
// }
230230
// });
231-
// rlUIAutoDivider.setOnTouchListener(new View.OnTouchListener() {
231+
// rlUIAutoSplitY.setOnTouchListener(new View.OnTouchListener() {
232232
// @Override
233233
// public boolean onTouch(View v, MotionEvent event) {
234234
//// 都不动了 if (event.getY() - event.getRawY() >= 10) {
235235
// if (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
236236
// moved = true;
237-
// divider.setY(event.getY());
238-
//// divider.invalidate();
237+
// split.setY(event.getY());
238+
//// split.invalidate();
239239
// } else {
240240
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
241241
// moved = false;
242242
// }
243243
// else if (event.getAction() == MotionEvent.ACTION_UP) {
244244
// if (! moved) {
245-
// ivUIAutoDivider.performClick();
245+
// ivUIAutoSplit.performClick();
246246
// }
247247
// }
248248
// }
@@ -297,8 +297,8 @@ protected void onCreate(Bundle savedInstanceState) {
297297
// s = "";
298298
// }
299299
//
300-
// float dividerY = floatDivider.getY() + rlUIAutoDivider.getHeight()/2;
301-
// float relativeY = event.getY() <= dividerY ? event.getY() : (event.getY() - screenHeight);
300+
// float splitY = floatSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
301+
// float relativeY = event.getY() <= splitY ? event.getY() : (event.getY() - screenHeight);
302302
//
303303
// tvTouch.setText(Calendar.getInstance().getTime().toLocaleString() + " " + InputUtil.getActionName(event.getAction()) + "\nx:" + event.getX() + "; y:" + event.getY() + "; relativeY: " + relativeY + "; pointerCount: " + event.getPointerCount() + "\n" + s);
304304
//// Toast.makeText(context, "vTouch.action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY(), Toast.LENGTH_SHORT).show();
@@ -387,12 +387,12 @@ public void record(View v) {
387387

388388

389389
// private IFloatWindow floatCover;
390-
// private IFloatWindow floatDivider;
390+
// private IFloatWindow floatSplitY;
391391
//
392392
// private void showCover(boolean show, Activity activity) {
393393
// //TODO 为纵屏、横屏分别加两套,判断屏幕方向来显示对应的一套
394-
//// rlUIAutoDivider.setVisibility(show ? View.VISIBLE : View.GONE);
395-
//// rlUIAutoDivider.setY(dividerY + dividerHeight/2);
394+
//// rlUIAutoSplitY.setVisibility(show ? View.VISIBLE : View.GONE);
395+
//// rlUIAutoSplitY.setY(splitY + splitHeight/2);
396396
//
397397
// floatCover = FloatWindow.get("v");
398398
// if (floatCover == null) {
@@ -415,26 +415,26 @@ public void record(View v) {
415415
// floatCover.show();
416416
//
417417
//
418-
// floatDivider = FloatWindow.get("v_ball");
419-
// if (floatDivider == null) {
418+
// floatSplitY = FloatWindow.get("v_ball");
419+
// if (floatSplitY == null) {
420420
// FloatWindow
421421
// .with(getApplicationContext())
422422
// .setTag("v_ball")
423-
// .setView(divider)
423+
// .setView(split)
424424
// .setWidth(windowWidth) //设置控件宽高
425-
// .setHeight((int) dividerHeight)
425+
// .setHeight((int) splitHeight)
426426
// .setX(0) //设置控件初始位置
427-
// .setY((int) (windowY + dividerY - dividerHeight/2))
427+
// .setY((int) (windowY + splitY - splitHeight/2))
428428
//// .setY(screenHeight/2)
429429
// .setMoveType(MoveType.slide)
430430
// .setDesktopShow(true) //必须为 true,否则切换 Activity 就会自动隐藏 //桌面显示
431431
//// .setViewStateListener(mViewStateListener) //监听悬浮控件状态改变
432432
//// .setPermissionListener(mPermissionListener) //监听权限申请结果
433433
// .build();
434434
//
435-
// floatDivider = FloatWindow.get("v_ball");
435+
// floatSplitY = FloatWindow.get("v_ball");
436436
// }
437-
// floatDivider.show();
437+
// floatSplitY.show();
438438
//
439439
// //TODO 新建一个 have already added to window manager
440440
//
@@ -458,11 +458,11 @@ public void record(View v) {
458458
//// FloatWindow
459459
//// .with(getApplicationContext())
460460
//// .setTag("h_ball")
461-
//// .setView(divider)
461+
//// .setView(split)
462462
//// .setWidth(screenWidth) //设置控件宽高
463-
//// .setHeight((int) dividerHeight)
463+
//// .setHeight((int) splitHeight)
464464
//// .setX(0) //设置控件初始位置
465-
//// .setY((int) (dividerY + dividerHeight/2))
465+
//// .setY((int) (splitY + splitHeight/2))
466466
////// .setY(screenHeight/2)
467467
//// .setMoveType(MoveType.slide)
468468
//// .setDesktopShow(true) //桌面显示
@@ -525,17 +525,17 @@ public void record(View v) {
525525
// }
526526
//
527527
//
528-
//// float dividerY = rlUIAutoDivider.getY() + rlUIAutoDivider.getHeight()/2;
529-
//// float dividerY = floatDivider.getY() + rlUIAutoDivider.getHeight()/2;
530-
//// float relativeY = event.getY() <= dividerY ? event.getY() : (event.getY() - screenHeight);
528+
//// float splitY = rlUIAutoSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
529+
//// float splitY = floatSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
530+
//// float relativeY = event.getY() <= splitY ? event.getY() : (event.getY() - screenHeight);
531531
////
532532
//// JSONObject obj = new JSONObject(true);
533533
//// obj.put("id", - System.currentTimeMillis());
534534
//// obj.put("flowId", flowId);
535535
//// obj.put("action", event.getAction());
536536
//// obj.put("x", (int) event.getX());
537537
//// obj.put("y", (int) relativeY);
538-
//// obj.put("dividerY", (int) dividerY);
538+
//// obj.put("splitY", (int) splitY);
539539
//// obj.put("rawX", (int) event.getRawX());
540540
//// obj.put("rawY", (int) event.getRawY());
541541
//// obj.put("time", System.currentTimeMillis());
@@ -576,7 +576,7 @@ public void record(View v) {
576576
//
577577
// @Override
578578
// protected void onDestroy() {
579-
// cache.edit().remove(DIVIDER_Y).putFloat(DIVIDER_Y, rlUIAutoDivider.getY() + rlUIAutoDivider.getHeight()/2).apply();
579+
// cache.edit().remove(SPLIT_Y).putFloat(SPLIT_Y, rlUIAutoSplitY.getY() + rlUIAutoSplitY.getHeight()/2).apply();
580580
// super.onDestroy();
581581
// }
582582
//
@@ -613,7 +613,7 @@ public void record(View v) {
613613
// firstCurTime = 0;
614614
// if (firstTime > 0) {
615615
// firstCurTime = System.currentTimeMillis();
616-
// pbUIAutoDivider.setVisibility(View.VISIBLE);
616+
// pbUIAutoSplit.setVisibility(View.VISIBLE);
617617
//
618618
// for (int i = 0; i < touchList.size(); i++) {
619619
// JSONObject obj = touchList.getJSONObject(i);
@@ -739,15 +739,15 @@ public void record(View v) {
739739
// }
740740
//
741741
// private JSONArray addInputEvent(InputEvent ie, Activity activity) {
742-
// int dividerY = floatDivider.getY() + rlUIAutoDivider.getHeight()/2;
742+
// int splitY = floatSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
743743
// int orientation = activity == null ? Configuration.ORIENTATION_PORTRAIT : activity.getResources().getConfiguration().orientation;
744744
//
745745
// JSONObject obj = new JSONObject(true);
746746
// obj.put("id", - System.currentTimeMillis());
747747
// obj.put("flowId", flowId);
748748
// obj.put("time", System.currentTimeMillis());
749749
// obj.put("orientation", orientation);
750-
// obj.put("dividerY", dividerY);
750+
// obj.put("splitY", splitY);
751751
//
752752
// if (ie instanceof KeyEvent) {
753753
// KeyEvent event = (KeyEvent) ie;
@@ -784,7 +784,7 @@ public void record(View v) {
784784
// obj.put("deviceId", event.getDeviceId());
785785
// //虽然 KeyEvent 和 MotionEvent 都有,但都不在父类 InputEvent 中 >>>>>>>>>>>>>>>>>>
786786
//
787-
// float relativeY = event.getY() <= dividerY ? event.getY() : (event.getY() - screenHeight);
787+
// float relativeY = event.getY() <= splitY ? event.getY() : (event.getY() - screenHeight);
788788
//
789789
// obj.put("x", (int) event.getX());
790790
// obj.put("y", (int) relativeY);

APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/ui/UIAutoBaseActivity.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ public abstract class UIAutoBaseActivity extends Activity {
3131
// DemoApplication.getInstance().onTouchEvent(event, this);
3232
// return super.onTouchEvent(event);
3333
// }
34+
//
3435

35-
@Override
36-
public boolean onKeyDown(int keyCode, KeyEvent event) {
37-
DemoApplication.getInstance().onKeyDown(keyCode, event, this);
38-
return super.onKeyDown(keyCode, event);
39-
}
4036

4137
@Override
42-
public boolean onKeyUp(int keyCode, KeyEvent event) {
43-
DemoApplication.getInstance().onKeyUp(keyCode, event, this);
44-
return super.onKeyUp(keyCode, event);
38+
public boolean dispatchKeyEvent(KeyEvent event) {
39+
DemoApplication.getInstance().addInputEvent(event, this);
40+
return super.dispatchKeyEvent(event);
4541
}
4642

43+
// @Override
44+
// public boolean onKeyDown(int keyCode, KeyEvent event) {
45+
// DemoApplication.getInstance().onKeyDown(keyCode, event, this);
46+
// return super.onKeyDown(keyCode, event);
47+
// }
48+
//
49+
// @Override
50+
// public boolean onKeyUp(int keyCode, KeyEvent event) {
51+
// DemoApplication.getInstance().onKeyUp(keyCode, event, this);
52+
// return super.onKeyUp(keyCode, event);
53+
// }
54+
4755
}

APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/ui/UIAutoListActivity.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ private void setList(List<String> list) {
203203
@Override
204204
public void run() {
205205
pbUIAutoList.setVisibility(View.GONE);
206-
adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, list);
207-
lvUIAutoList.setAdapter(adapter);
206+
if (adapter == null) {
207+
adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, list);
208+
lvUIAutoList.setAdapter(adapter);
209+
} else {
210+
adapter.clear();
211+
adapter.addAll(list);
212+
adapter.notifyDataSetChanged();
213+
}
208214
}
209215
});
210216
}
@@ -232,13 +238,13 @@ public void run() {
232238
if (obj.getIntValue("type") == 1) {
233239
list.add("[" + state + "] " + new Date(obj.getLongValue("time")).toLocaleString() + " " + InputUtil.getActionName(obj.getIntValue("action"))
234240
+ "\nrepeatCount: " + obj.getString("repeatCount") + ", scanCode: " + InputUtil.getScanCodeName(obj.getIntValue("scanCode")) + " " + InputUtil.getKeyCodeName(obj.getIntValue("keyCode"))
235-
+ "\nsplitX: " + obj.getString("splitX") + ", splitY: " + obj.getString("dividerY") + " " + InputUtil.getOrientationName(obj.getIntValue("orientation"))
241+
+ "\nsplitX: " + obj.getString("splitX") + ", splitY: " + obj.getString("splitY") + " " + InputUtil.getOrientationName(obj.getIntValue("orientation"))
236242
);
237243
}
238244
else {
239245
list.add("[" + state + "] " + new Date(obj.getLongValue("time")).toLocaleString() + " " + InputUtil.getActionName(obj.getIntValue("action"))
240246
+ "\npointerCount: " + obj.getString("pointerCount") + ", x: " + obj.getString("x") + ", y: " + obj.getString("y")
241-
+ "\nsplitX: " + obj.getString("splitX") + ", splitY: " + obj.getString("dividerY") + " " + InputUtil.getOrientationName(obj.getIntValue("orientation"))
247+
+ "\nsplitX: " + obj.getString("splitX") + ", splitY: " + obj.getString("splitY") + " " + InputUtil.getOrientationName(obj.getIntValue("orientation"))
242248
);
243249
}
244250
} else {

0 commit comments

Comments
 (0)