Skip to content

Commit 4acfd0b

Browse files
committed
Android:APIJSONTest 自动 UI 测试初步完成记录和回放按键事件
1 parent d1d0682 commit 4acfd0b

File tree

4 files changed

+275
-71
lines changed

4 files changed

+275
-71
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.support.annotation.Nullable;
77
import android.util.AttributeSet;
88
import android.util.Log;
9+
import android.view.KeyEvent;
910
import android.view.MotionEvent;
1011
import android.widget.RelativeLayout;
1112

@@ -45,4 +46,33 @@ public boolean onTouchEvent(MotionEvent ev) {
4546
super.onTouchEvent(ev);
4647
return false;
4748
}
49+
50+
@Override
51+
public boolean onKeyDown(int keyCode, KeyEvent event) {
52+
super.onKeyDown(keyCode, event);
53+
54+
return false;
55+
}
56+
57+
@Override
58+
public boolean onKeyUp(int keyCode, KeyEvent event) {
59+
super.onKeyUp(keyCode, event);
60+
61+
return false;
62+
}
63+
64+
65+
66+
private static class Node<E> {
67+
E item;
68+
Node<E> next;
69+
Node<E> prev;
70+
71+
Node(Node<E> prev, E element, Node<E> next) {
72+
this.item = element;
73+
this.next = next;
74+
this.prev = prev;
75+
}
76+
}
77+
4878
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package apijson.demo.ui;
22

3+
import android.content.res.Configuration;
4+
import android.view.KeyEvent;
35
import android.view.MotionEvent;
46

57
public class TouchUtil {
@@ -22,4 +24,16 @@ public static String getActionName(int action) {
2224
return "CANCEL";
2325
}
2426
}
27+
28+
public static String getOrientationName(int orientation) {
29+
return orientation == Configuration.ORIENTATION_LANDSCAPE ? "HORIZONTAL" : "VERTICAL";
30+
}
31+
32+
public static String getKeyCodeName(int keyCode) {
33+
return KeyEvent.keyCodeToString(keyCode);
34+
}
35+
36+
public static String getScanCodeName(int scanCode) {
37+
return "" + scanCode; //它是 hardware key id KeyEvent.keyCodeToString(scanCode);
38+
}
2539
}

0 commit comments

Comments
 (0)