Skip to content

Commit 6a9a9bf

Browse files
committed
Android:APIJSONTest 新增 UIAutoActivity;重命名 UnitActivity 为 UnitAutoActivity
1 parent aa7bbd7 commit 6a9a9bf

File tree

11 files changed

+294
-35
lines changed

11 files changed

+294
-35
lines changed

APIJSON-Android/APIJSONTest/app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@
4242
android:screenOrientation="userLandscape"
4343
/>
4444
<activity
45-
android:name="apijson.demo.ui.UnitActivity"
45+
android:name="apijson.demo.ui.UnitAutoActivity"
4646
android:label="@string/unit"
4747
android:windowSoftInputMode="adjustPan"
4848
android:configChanges="orientation|screenSize"
4949
android:screenOrientation="userLandscape"
5050
/>
51+
<activity
52+
android:name="apijson.demo.ui.UIAutoActivity"
53+
android:label="@string/ui"
54+
android:windowSoftInputMode="adjustPan"
55+
android:configChanges="orientation|screenSize"
56+
android:screenOrientation="portrait"
57+
/>
5158
</application>
5259

5360
</manifest>

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,32 @@
1414

1515
package apijson.demo;
1616

17-
import java.io.IOException;
18-
import java.net.CookieHandler;
19-
import java.net.URI;
20-
import java.util.ArrayList;
21-
import java.util.HashMap;
22-
import java.util.List;
23-
import java.util.Map;
24-
import java.util.concurrent.TimeUnit;
25-
26-
import org.json.JSONException;
27-
import org.json.JSONObject;
28-
29-
import zuo.biao.apijson.StringUtil;
3017
import android.content.Context;
3118
import android.os.AsyncTask;
3219
import android.text.TextUtils;
3320
import android.util.Log;
34-
import apijson.demo.application.DemoApplication;
3521

3622
import com.squareup.okhttp.MediaType;
3723
import com.squareup.okhttp.OkHttpClient;
3824
import com.squareup.okhttp.Request;
3925
import com.squareup.okhttp.RequestBody;
4026
import com.squareup.okhttp.Response;
4127

28+
import org.json.JSONException;
29+
import org.json.JSONObject;
30+
31+
import java.io.IOException;
32+
import java.net.CookieHandler;
33+
import java.net.URI;
34+
import java.util.ArrayList;
35+
import java.util.HashMap;
36+
import java.util.List;
37+
import java.util.Map;
38+
import java.util.concurrent.TimeUnit;
39+
40+
import apijson.demo.application.DemoApplication;
41+
import zuo.biao.apijson.StringUtil;
42+
4243
/**HTTP请求管理类
4344
* @author Lemon
4445
* @use HttpManager.getInstance().get(...)或HttpManager.getInstance().post(...) > 在回调方法onHttpRequestSuccess和onHttpRequestError处理HTTP请求结果
@@ -137,12 +138,8 @@ public synchronized static HttpManager getInstance() {
137138
public static final MediaType TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
138139

139140
/**POST请求
140-
* @param paramList 请求参数列表,(可以一个键对应多个值)
141-
* @param url 接口url
142-
* @param requestCode
143-
* 请求码,类似onActivityResult中请求码,当同一activity中以实现接口方式发起多个网络请求时,请求结束后都会回调
144-
* {@link OnHttpResponseListener#onHttpResponse(int, String, Exception)}<br/>
145-
* 在发起请求的类中可以用requestCode来区分各个请求
141+
* @param url_ 接口url
142+
* @param request 请求参数,(可以一个键对应多个值)
146143
* @param listener
147144
*/
148145
public void post(final String url_, final String request, final OnHttpResponseListener listener) {
@@ -208,7 +205,7 @@ private OkHttpClient getHttpClient(String url) {
208205
}
209206

210207
/**
211-
* @param paramList
208+
* @param tag
212209
* @must demo_***改为服务器设定值
213210
* @return
214211
*/
@@ -266,7 +263,7 @@ private String getResponseJson(OkHttpClient client, Request request) throws Exce
266263
* @param json
267264
* @param key
268265
* @return
269-
* @throws JSONException
266+
* @throws JSONException
270267
*/
271268
public <T> T getValue(String json, String key) throws JSONException {
272269
return getValue(new JSONObject(json), key);
@@ -276,7 +273,7 @@ public <T> T getValue(String json, String key) throws JSONException {
276273
* @param object
277274
* @param key
278275
* @return
279-
* @throws JSONException
276+
* @throws JSONException
280277
*/
281278
@SuppressWarnings("unchecked")
282279
public <T> T getValue(JSONObject object, String key) throws JSONException {

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
115
package apijson.demo.ui;
216

17+
import com.alibaba.fastjson.JSONArray;
18+
import com.alibaba.fastjson.JSONObject;
19+
320
import java.util.Set;
421

22+
import apijson.demo.StringUtil;
523
import zuo.biao.apijson.JSONRequest;
624
import zuo.biao.apijson.JSONResponse;
7-
import apijson.demo.StringUtil;
8-
9-
import com.alibaba.fastjson.JSONArray;
10-
import com.alibaba.fastjson.JSONObject;
1125

26+
/**生成代码的工具类
27+
* @author Lemon
28+
*/
1229
public class CodeUtil {
1330

1431

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
@@ -124,7 +124,11 @@ public void toAuto(View v) {
124124
}
125125

126126
public void toUnit(View v) {
127-
startActivity(UnitActivity.createIntent(context));
127+
startActivity(UnitAutoActivity.createIntent(context));
128+
}
129+
130+
public void toUI(View v) {
131+
startActivity(UIAutoActivity.createIntent(context));
128132
}
129133

130134
public void toUpdateLog(View v) {
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package apijson.demo.ui;
16+
17+
import android.app.Activity;
18+
import android.content.Context;
19+
import android.content.Intent;
20+
import android.os.Bundle;
21+
import android.os.Handler;
22+
import android.view.Display;
23+
import android.view.MotionEvent;
24+
import android.view.View;
25+
import android.widget.ScrollView;
26+
import android.widget.TextView;
27+
import android.widget.Toast;
28+
29+
import java.util.Calendar;
30+
31+
import apijson.demo.R;
32+
33+
34+
/**自动 UI 测试,需要用 UIAuto 发请求到这个设备
35+
* https://github.com/TommyLemon/UIAuto
36+
* @author Lemon
37+
*/
38+
public class UIAutoActivity extends Activity {
39+
/**
40+
* @param context
41+
* @return
42+
*/
43+
public static Intent createIntent(Context context) {
44+
return new Intent(context, UIAutoActivity.class);
45+
}
46+
47+
private Activity context;
48+
@Override
49+
protected void onCreate(Bundle savedInstanceState) {
50+
super.onCreate(savedInstanceState);
51+
setContentView(R.layout.ui_auto_activity);
52+
context = this;
53+
54+
final Display d = getWindowManager().getDefaultDisplay();
55+
56+
final ScrollView svTouch = findViewById(R.id.svTouch);
57+
final TextView tvTouch = findViewById(R.id.tvTouch);
58+
59+
final View tvButton = findViewById(R.id.tvButton);
60+
final View btnButton = findViewById(R.id.btnButton);
61+
62+
final View vTouch = findViewById(R.id.vTouch);
63+
final View llTouch = findViewById(R.id.llTouch);
64+
final View rlRoot = findViewById(R.id.rlRoot);
65+
final View vDispatchTouch = findViewById(R.id.vDispatchTouch);
66+
67+
68+
View.OnTouchListener listener = new View.OnTouchListener() {
69+
@Override
70+
public boolean onTouch(View v, MotionEvent event) {
71+
vDispatchTouch.dispatchTouchEvent(event);
72+
73+
// vTouch.setOnTouchListener(new View.OnTouchListener() {
74+
// @Override
75+
// public boolean onTouch(View v, MotionEvent event) {
76+
// return false;
77+
// }
78+
// });
79+
//
80+
CharSequence s = tvTouch.getText();
81+
if (s == null) {
82+
s = "";
83+
}
84+
85+
tvTouch.setText(Calendar.getInstance().getTime().toLocaleString() + " action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY() + "\n" + s);
86+
// Toast.makeText(context, "vTouch.action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY(), Toast.LENGTH_SHORT).show();
87+
88+
//死循环 llTouch.dispatchTouchEvent(event);
89+
// vDispatchTouch.dispatchTouchEvent(event);
90+
// vDispatchTouch.dispatchTouchEvent(event);
91+
//onTouchEvent 不能处理事件 vDispatchTouch.onTouchEvent(event);
92+
// vTouch.setOnTouchListener(this);
93+
return true; //连续记录只能 return true
94+
}
95+
};
96+
vTouch.setOnTouchListener(listener);
97+
98+
tvButton.setOnClickListener(new View.OnClickListener() {
99+
@Override
100+
public void onClick(View v) {
101+
Toast.makeText(context, "tvButton.onClick", Toast.LENGTH_SHORT).show();
102+
}
103+
});
104+
tvButton.setOnTouchListener(new View.OnTouchListener() {
105+
@Override
106+
public boolean onTouch(View v, MotionEvent event) {
107+
Toast.makeText(context, "tvButton.action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY(), Toast.LENGTH_SHORT).show();
108+
return false; //连续记录只能 return true
109+
}
110+
});
111+
112+
btnButton.setOnLongClickListener(new View.OnLongClickListener() {
113+
@Override
114+
public boolean onLongClick(View v) {
115+
Toast.makeText(context, "btnMain.onLongClick", Toast.LENGTH_SHORT).show();
116+
return true;
117+
}
118+
});
119+
120+
121+
new Handler().postDelayed(new Runnable() {
122+
@Override
123+
public void run() {
124+
125+
MotionEvent e = MotionEvent.obtain(1000, 1000,
126+
MotionEvent.ACTION_DOWN, d.getWidth()/2, d.getHeight()/2, 0);
127+
128+
//TODO onTouchEvent ?
129+
vTouch.dispatchTouchEvent(e);
130+
e.setAction(MotionEvent.ACTION_UP);
131+
vTouch.dispatchTouchEvent(e);
132+
133+
}
134+
}, 1000);
135+
}
136+
137+
138+
public void onClick(View v) {
139+
Toast.makeText(context, "onClick BUTTON", Toast.LENGTH_SHORT).show();
140+
}
141+
}

APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/ui/UnitActivity.java renamed to APIJSON-Android/APIJSONTest/app/src/main/java/apijson/demo/ui/UnitAutoActivity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@
5050
* https://github.com/TommyLemon/UnitAuto
5151
* @author Lemon
5252
*/
53-
public class UnitActivity extends Activity implements HttpServerRequestCallback {
54-
private static final String TAG = "UnitActivity";
53+
public class UnitAutoActivity extends Activity implements HttpServerRequestCallback {
54+
private static final String TAG = "UnitAutoActivity";
5555
private static final String KEY_PORT = "KEY_PORT";
5656

5757
/**
5858
* @param context
5959
* @return
6060
*/
6161
public static Intent createIntent(Context context) {
62-
return new Intent(context, UnitActivity.class);
62+
return new Intent(context, UnitAutoActivity.class);
6363
}
6464

6565

@@ -79,7 +79,7 @@ public static Intent createIntent(Context context) {
7979
protected void onCreate(Bundle savedInstanceState) {
8080
super.onCreate(savedInstanceState);
8181
requestWindowFeature(Window.FEATURE_NO_TITLE);
82-
setContentView(R.layout.unit_activity);
82+
setContentView(R.layout.unit_auto_activity);
8383
context = this;
8484
isAlive = true;
8585

@@ -250,7 +250,7 @@ public void complete(JSONObject data, Method method, MethodUtil.InterfaceProxy p
250250
String clsName = req.getString("class");
251251
Class<?> clazz = Class.forName(pkgName.replaceAll("/", ".") + "." + clsName);
252252
if (clazz.isAssignableFrom(Activity.class)) {
253-
instance = UnitActivity.this;
253+
instance = UnitAutoActivity.this;
254254
} else if (clazz.isAssignableFrom(Application.class)) {
255255
instance = DemoApplication.getInstance();
256256
} else {

APIJSON-Android/APIJSONTest/app/src/main/res/layout/select_activity.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
android:onClick="toUnit"
111111
android:text="@string/unit" />
112112

113+
<Button
114+
style="@style/match_wrap"
115+
android:layout_marginTop="30dp"
116+
android:onClick="toUI"
117+
android:text="@string/ui" />
118+
113119
<Button
114120
android:onClick="toUpdateLog"
115121
style="@style/match_wrap"

0 commit comments

Comments
 (0)